]> granicus.if.org Git - python/commitdiff
bpo-33792: Add selector and proactor windows policies (GH-7487)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 8 Jun 2018 01:31:50 +0000 (18:31 -0700)
committerGitHub <noreply@github.com>
Fri, 8 Jun 2018 01:31:50 +0000 (18:31 -0700)
(cherry picked from commit 8f4042964d5b0ddf5cdf87862db962ba64e3f64a)

Co-authored-by: Yury Selivanov <yury@magic.io>
Doc/whatsnew/3.7.rst
Lib/asyncio/windows_events.py
Lib/test/test_asyncio/test_windows_events.py
Misc/NEWS.d/next/Library/2018-06-07-12-38-12.bpo-33792.3aKG7u.rst [new file with mode: 0644]

index 3fe909ee978c24651142ebce6c0e6f2e9c7d7f9f..9a6f542ec479ec97fe997ae30da29029961eb277 100644 (file)
@@ -733,6 +733,10 @@ include:
 * Exceptions occurring in cancelled tasks are no longer logged.
   (Contributed by Yury Selivanov in :issue:`30508`.)
 
+* New ``WindowsSelectorEventLoopPolicy`` and
+  ``WindowsProactorEventLoopPolicy`` classes.
+  (Contributed by Yury Selivanov in :issue:`33792`.)
+
 Several ``asyncio`` APIs have been
 :ref:`deprecated <whatsnew37-asyncio-deprecated>`.
 
index d22edec51efc1fbde3c1a01a3569a7b4ec0d0789..2ec542764375e9b4a177a79226acaa69d0e6b6a3 100644 (file)
@@ -21,7 +21,8 @@ from .log import logger
 
 __all__ = (
     'SelectorEventLoop', 'ProactorEventLoop', 'IocpProactor',
-    'DefaultEventLoopPolicy',
+    'DefaultEventLoopPolicy', 'WindowsSelectorEventLoopPolicy',
+    'WindowsProactorEventLoopPolicy',
 )
 
 
@@ -801,8 +802,12 @@ class _WindowsSubprocessTransport(base_subprocess.BaseSubprocessTransport):
 SelectorEventLoop = _WindowsSelectorEventLoop
 
 
-class _WindowsDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
+class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
     _loop_factory = SelectorEventLoop
 
 
-DefaultEventLoopPolicy = _WindowsDefaultEventLoopPolicy
+class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
+    _loop_factory = ProactorEventLoop
+
+
+DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy
index e4ff7fc7dd4ee888138de51ea08e4defdb80b432..15d933da21be1c2b450fad46f9b20f55f3266b1f 100644 (file)
@@ -162,5 +162,36 @@ class ProactorTests(test_utils.TestCase):
         fut.cancel()
 
 
+class WinPolicyTests(test_utils.TestCase):
+
+    def test_selector_win_policy(self):
+        async def main():
+            self.assertIsInstance(
+                asyncio.get_running_loop(),
+                asyncio.SelectorEventLoop)
+
+        old_policy = asyncio.get_event_loop_policy()
+        try:
+            asyncio.set_event_loop_policy(
+                asyncio.WindowsSelectorEventLoopPolicy())
+            asyncio.run(main())
+        finally:
+            asyncio.set_event_loop_policy(old_policy)
+
+    def test_proactor_win_policy(self):
+        async def main():
+            self.assertIsInstance(
+                asyncio.get_running_loop(),
+                asyncio.ProactorEventLoop)
+
+        old_policy = asyncio.get_event_loop_policy()
+        try:
+            asyncio.set_event_loop_policy(
+                asyncio.WindowsProactorEventLoopPolicy())
+            asyncio.run(main())
+        finally:
+            asyncio.set_event_loop_policy(old_policy)
+
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/Misc/NEWS.d/next/Library/2018-06-07-12-38-12.bpo-33792.3aKG7u.rst b/Misc/NEWS.d/next/Library/2018-06-07-12-38-12.bpo-33792.3aKG7u.rst
new file mode 100644 (file)
index 0000000..8c01764
--- /dev/null
@@ -0,0 +1,2 @@
+Add asyncio.WindowsSelectorEventLoopPolicy and
+asyncio.WindowsProactorEventLoopPolicy.