Skip to content

Commit

Permalink
bpo-33792: Add selector and proactor windows policies (GH-7487)
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Jun 8, 2018
1 parent 52698c7 commit 8f40429
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`.

Expand Down
11 changes: 8 additions & 3 deletions Lib/asyncio/windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

__all__ = (
'SelectorEventLoop', 'ProactorEventLoop', 'IocpProactor',
'DefaultEventLoopPolicy',
'DefaultEventLoopPolicy', 'WindowsSelectorEventLoopPolicy',
'WindowsProactorEventLoopPolicy',
)


Expand Down Expand Up @@ -801,8 +802,12 @@ def callback(f):
SelectorEventLoop = _WindowsSelectorEventLoop


class _WindowsDefaultEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
_loop_factory = SelectorEventLoop


DefaultEventLoopPolicy = _WindowsDefaultEventLoopPolicy
class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
_loop_factory = ProactorEventLoop


DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy
31 changes: 31 additions & 0 deletions Lib/test/test_asyncio/test_windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,36 @@ def test_wait_for_handle_cancel(self):
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add asyncio.WindowsSelectorEventLoopPolicy and
asyncio.WindowsProactorEventLoopPolicy.

0 comments on commit 8f40429

Please sign in to comment.