diff options
author | Yury Selivanov <yury@magic.io> | 2018-06-07 20:44:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-07 20:44:57 -0400 |
commit | 8f4042964d5b0ddf5cdf87862db962ba64e3f64a (patch) | |
tree | bdfe505b29985bf5fdbbec72bf1a9cd5e4856419 /Lib | |
parent | 52698c7ad9eae9feb35839fde17a7d1da8036a9b (diff) | |
download | cpython-git-8f4042964d5b0ddf5cdf87862db962ba64e3f64a.tar.gz |
bpo-33792: Add selector and proactor windows policies (GH-7487)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/asyncio/windows_events.py | 11 | ||||
-rw-r--r-- | Lib/test/test_asyncio/test_windows_events.py | 31 |
2 files changed, 39 insertions, 3 deletions
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py index d22edec51e..2ec5427643 100644 --- a/Lib/asyncio/windows_events.py +++ b/Lib/asyncio/windows_events.py @@ -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 diff --git a/Lib/test/test_asyncio/test_windows_events.py b/Lib/test/test_asyncio/test_windows_events.py index f92911ea3b..8f4c50e2c9 100644 --- a/Lib/test/test_asyncio/test_windows_events.py +++ b/Lib/test/test_asyncio/test_windows_events.py @@ -166,5 +166,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() |