Skip to content

Commit feabc5d

Browse files
committed
bpo-33792: Add selector and proactor windows policies
1 parent 378c53c commit feabc5d

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
@@ -166,5 +166,36 @@ def test_wait_for_handle_cancel(self):
166166
fut.cancel()
167167

168168

169+
class WinPolicyTests(test_utils.TestCase):
170+
171+
def test_selector_win_policy(self):
172+
async def main():
173+
self.assertIsInstance(
174+
asyncio.get_running_loop(),
175+
asyncio.SelectorEventLoop)
176+
177+
old_policy = asyncio.get_event_loop_policy()
178+
try:
179+
asyncio.set_event_loop_policy(
180+
asyncio.WindowsSelectorEventLoopPolicy())
181+
asyncio.run(main())
182+
finally:
183+
asyncio.set_event_loop_policy(old_policy)
184+
185+
def test_proactor_win_policy(self):
186+
async def main():
187+
self.assertIsInstance(
188+
asyncio.get_running_loop(),
189+
asyncio.ProactorEventLoop)
190+
191+
old_policy = asyncio.get_event_loop_policy()
192+
try:
193+
asyncio.set_event_loop_policy(
194+
asyncio.WindowsProactorEventLoopPolicy())
195+
asyncio.run(main())
196+
finally:
197+
asyncio.set_event_loop_policy(old_policy)
198+
199+
169200
if __name__ == '__main__':
170201
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)