Skip to content

Commit

Permalink
pythonGH-94597 add asyncio.EventLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 11, 2023
1 parent eb50cd3 commit d2f7090
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Doc/library/asyncio-eventloop.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,14 @@ on Unix and :class:`ProactorEventLoop` on Windows.
`MSDN documentation on I/O Completion Ports
<https://docs.microsoft.com/en-ca/windows/desktop/FileIO/i-o-completion-ports>`_.

.. class:: EventLoop

Uses the most effiecient available event loop for the given
platform.

.. versionadded:: 3.13

.. availability:: Unix, Windows.

.. class:: AbstractEventLoop

Expand Down
2 changes: 2 additions & 0 deletions Doc/library/asyncio-runner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Running an asyncio Program
This function should be used as a main entry point for asyncio programs,
and should ideally only be called once. It is recommended to use
*loop_factory* to configure the event loop instead of policies.
Passing :class:`asyncio.EventLoop` allows running asyncio without the
policy system.

The executor is given a timeout duration of 5 minutes to shutdown.
If the executor hasn't finished within that duration, a warning is
Expand Down
1 change: 1 addition & 0 deletions Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,3 +1510,4 @@ def set_child_watcher(self, watcher):

SelectorEventLoop = _UnixSelectorEventLoop
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
EventLoop = SelectorEventLoop
1 change: 1 addition & 0 deletions Lib/asyncio/windows_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,3 +894,4 @@ class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):


DefaultEventLoopPolicy = WindowsProactorEventLoopPolicy
EventLoop = ProactorEventLoop
10 changes: 10 additions & 0 deletions Lib/test/test_asyncio/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ async def main():
asyncio.run(main(), loop_factory=factory)
factory.assert_called_once_with()

def test_loop_factory_default_event_loop(self):
async def main():
if sys.platform == "win32":
self.assertIsInstance(asyncio.get_running_loop(), asyncio.ProactorEventLoop)
else:
self.assertIsInstance(asyncio.get_running_loop(), asyncio.SelectorEventLoop)


asyncio.run(main(), loop_factory=asyncio.EventLoop)


class RunnerTests(BaseTest):

Expand Down

0 comments on commit d2f7090

Please sign in to comment.