* :mod:`asyncio`:
* :func:`!asyncio.iscoroutinefunction` is deprecated
- and will be removed in Python 3.16,
+ and will be removed in Python 3.16;
use :func:`inspect.iscoroutinefunction` instead.
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.)
+ * :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16.
+ In particular, the following classes and functions are deprecated:
+
+ * :class:`asyncio.AbstractEventLoopPolicy`
+ * :class:`asyncio.DefaultEventLoopPolicy`
+ * :class:`asyncio.WindowsSelectorEventLoopPolicy`
+ * :class:`asyncio.WindowsProactorEventLoopPolicy`
+ * :func:`asyncio.get_event_loop_policy`
+ * :func:`asyncio.set_event_loop_policy`
+ * :func:`asyncio.set_event_loop`
+
+ Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
+ *loop_factory* to use the desired event loop implementation.
+
+ For example, to use :class:`asyncio.SelectorEventLoop` on Windows::
+
+ import asyncio
+
+ async def main():
+ ...
+
+ asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
+
+ (Contributed by Kumar Aditya in :gh:`127949`.)
+
* :mod:`builtins`:
* Bitwise inversion on boolean types, ``~True`` or ``~False``
.. versionchanged:: 3.14
Raises a :exc:`RuntimeError` if there is no current event loop.
+ .. note::
+
+ The :mod:`!asyncio` policy system is deprecated and will be removed
+ in Python 3.16; from there on, this function will always return the
+ running event loop.
+
+
.. function:: set_event_loop(loop)
Set *loop* as the current event loop for the current OS thread.
import asyncio
import selectors
- class MyPolicy(asyncio.DefaultEventLoopPolicy):
- def new_event_loop(self):
- selector = selectors.SelectSelector()
- return asyncio.SelectorEventLoop(selector)
+ async def main():
+ ...
- asyncio.set_event_loop_policy(MyPolicy())
+ loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector())
+ asyncio.run(main(), loop_factory=loop_factory)
.. availability:: Unix, Windows.
*coro* can be any awaitable object.
+ .. note::
+
+ The :mod:`!asyncio` policy system is deprecated and will be removed
+ in Python 3.16; from there on, an explicit *loop_factory* is needed
+ to configure the event loop.
+
Runner context manager
======================