This is needed to pave the way for deprecating and eventually killing the event loop policy system (which is over-engineered and rarely used).
asyncio ships with two different event loop implementations:
:class:`SelectorEventLoop` and :class:`ProactorEventLoop`.
-By default asyncio is configured to use :class:`SelectorEventLoop`
-on Unix and :class:`ProactorEventLoop` on Windows.
+By default asyncio is configured to use :class:`EventLoop`.
.. class:: SelectorEventLoop
- An event loop based on the :mod:`selectors` module.
+ A subclass of :class:`AbstractEventLoop` based on the
+ :mod:`selectors` module.
Uses the most efficient *selector* available for the given
platform. It is also possible to manually configure the
.. class:: ProactorEventLoop
- An event loop for Windows that uses "I/O Completion Ports" (IOCP).
+ A subclass of :class:`AbstractEventLoop` for Windows that uses "I/O Completion Ports" (IOCP).
.. availability:: Windows.
`MSDN documentation on I/O Completion Ports
<https://docs.microsoft.com/en-ca/windows/desktop/FileIO/i-o-completion-ports>`_.
+.. class:: EventLoop
+
+ An alias to the most efficient available subclass of :class:`AbstractEventLoop` for the given
+ platform.
+
+ It is an alias to :class:`SelectorEventLoop` on Unix and :class:`ProactorEventLoop` on Windows.
+
+ .. versionadded:: 3.13
.. class:: AbstractEventLoop
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
'FastChildWatcher', 'PidfdChildWatcher',
'MultiLoopChildWatcher', 'ThreadedChildWatcher',
'DefaultEventLoopPolicy',
+ 'EventLoop',
)
SelectorEventLoop = _UnixSelectorEventLoop
DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy
+EventLoop = SelectorEventLoop
__all__ = (
'SelectorEventLoop', 'ProactorEventLoop', 'IocpProactor',
'DefaultEventLoopPolicy', 'WindowsSelectorEventLoopPolicy',
- 'WindowsProactorEventLoopPolicy',
+ 'WindowsProactorEventLoopPolicy', 'EventLoop',
)
DefaultEventLoopPolicy = WindowsProactorEventLoopPolicy
+EventLoop = ProactorEventLoop
import contextvars
import re
import signal
+import sys
import threading
import unittest
from test.test_asyncio import utils as test_utils
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):
--- /dev/null
+Added :class:`asyncio.EventLoop` for use with the :func:`asyncio.run` *loop_factory* kwarg to avoid calling the asyncio policy system.