8000 bpo-33792: Add selector and proactor windows policies (GH-7487) · python/cpython@0738443 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0738443

Browse files
miss-islington1st1
andauthored
bpo-33792: Add selector and proactor windows policies (GH-7487)
(cherry picked from commit 8f40429) Co-authored-by: Yury Selivanov <yury@magic.io>
1 parent a971a6f commit 0738443

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

Doc/whatsnew/3.7.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ include:
733733
* Exceptions occurring in cancelled tasks are no longer logged.
734734
(Contributed by Yury Selivanov in :issue:`30508`.)
735735

736+
* New ``WindowsSelectorEventLoopPolicy`` and
737+
``WindowsProactorEventLoopPolicy`` classes.
738+
(Contributed by Yury Selivanov in :issue:`33792`.)
739+
736740
Several ``asyncio`` APIs have been
737741
:ref:`deprecated <whatsnew37-asyncio-deprecated>`.
738742

Lib/asyncio/windows_events.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
__all__ = (
2323
'SelectorEventLoop', 'ProactorEventLoop', 'IocpProactor',
24-
'DefaultEventLoopPolicy',
24+
'DefaultEventLoopPolicy', 'WindowsSelectorEventLoopPolicy',
25+
'WindowsProactorEventLoopPolicy',
2526
)
2627

2728

@@ -801,8 +802,12 @@ def callback(f):
801802
SelectorEventLoop = _WindowsSelectorEventLoop
802803

803804

804-
class _WindowsDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
805+
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
805806
_loop_factory = SelectorEventLoop
806807

807808

808-
DefaultEventLoopPolicy = _WindowsDefaultEventLoopPolicy
809+
class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
810+
_loop_factory = ProactorEventLoop
811+
812+
813+
DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy

Lib/test/test_asyncio/test_windows_events.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,36 @@ def test_wait_for_handle_cancel(self):
162162
fut.cancel()
163163

164164

165+
class WinPolicyTests(test_utils.TestCase):
166+
167+
def test_selector_win_policy(self):
168+
async def main():
169+
self.assertIsInstance(
170+
asyncio.get_running_loop(),
171+
asyncio.SelectorEventLoop)
172+
173+
old_policy = asyncio.get_event_loop_policy()
174+
try:
175+
asyncio.set_event_loop_policy(
176+
asyncio.WindowsSelectorEventLoopPolicy())
177+
asyncio.run(main())
178+
finally:
179+
asyncio.set_event_loop_policy(old_policy)
180+
181+
def test_proactor_win_policy(self):
182+
async def main():
183+
self.assertIsInstance(
184+
asyncio.get_running_loop(),
185+
asyncio.ProactorEventLoop)
186+
187+
old_policy = asyncio.get_event_loop_policy()
188+
try:
189+
asyncio.set_event_loop_policy(
190+
asyncio.WindowsProactorEventLoopPolicy())
191+
asyncio.run(main())
192+
finally:
193+
asyncio.set_event_loop_policy(old_policy)
194+
195+
165196
if __name__ == '__main__':
166197
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add asyncio.WindowsSelectorEventLoopPolicy and
2+
asyncio.WindowsProactorEventLoopPolicy.

0 commit comments

Comments
 (0)
0