Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 64173cd

Browse filesBrowse files
gh-127949: make deprecation of policy system more prominent (#128290)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parent 71de839 commit 64173cd
Copy full SHA for 64173cd

File tree

3 files changed

+43
-6
lines changed
Filter options

3 files changed

+43
-6
lines changed

‎Doc/deprecations/pending-removal-in-3.16.rst

Copy file name to clipboardExpand all lines: Doc/deprecations/pending-removal-in-3.16.rst
+26-1Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,35 @@ Pending removal in Python 3.16
1919
* :mod:`asyncio`:
2020

2121
* :func:`!asyncio.iscoroutinefunction` is deprecated
22-
and will be removed in Python 3.16,
22+
and will be removed in Python 3.16;
2323
use :func:`inspect.iscoroutinefunction` instead.
2424
(Contributed by Jiahao Li and Kumar Aditya in :gh:`122875`.)
2525

26+
* :mod:`asyncio` policy system is deprecated and will be removed in Python 3.16.
27+
In particular, the following classes and functions are deprecated:
28+
29+
* :class:`asyncio.AbstractEventLoopPolicy`
30+
* :class:`asyncio.DefaultEventLoopPolicy`
31+
* :class:`asyncio.WindowsSelectorEventLoopPolicy`
32+
* :class:`asyncio.WindowsProactorEventLoopPolicy`
33+
* :func:`asyncio.get_event_loop_policy`
34+
* :func:`asyncio.set_event_loop_policy`
35+
* :func:`asyncio.set_event_loop`
36+
37+
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
38+
*loop_factory* to use the desired event loop implementation.
39+
40+
For example, to use :class:`asyncio.SelectorEventLoop` on Windows::
41+
42+
import asyncio
43+
44+
async def main():
45+
...
46+
47+
asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
48+
49+
(Contributed by Kumar Aditya in :gh:`127949`.)
50+
2651
* :mod:`builtins`:
2752

2853
* Bitwise inversion on boolean types, ``~True`` or ``~False``

‎Doc/library/asyncio-eventloop.rst

Copy file name to clipboardExpand all lines: Doc/library/asyncio-eventloop.rst
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ an event loop:
6262
.. versionchanged:: 3.14
6363
Raises a :exc:`RuntimeError` if there is no current event loop.
6464

65+
.. note::
66+
67+
The :mod:`!asyncio` policy system is deprecated and will be removed
68+
in Python 3.16; from there on, this function will always return the
69+
running event loop.
70+
71+
6572
.. function:: set_event_loop(loop)
6673

6774
Set *loop* as the current event loop for the current OS thread.
@@ -1781,12 +1788,11 @@ By default asyncio is configured to use :class:`EventLoop`.
17811788
import asyncio
17821789
import selectors
17831790

1784-
class MyPolicy(asyncio.DefaultEventLoopPolicy):
1785-
def new_event_loop(self):
1786-
selector = selectors.SelectSelector()
1787-
return asyncio.SelectorEventLoop(selector)
1791+
async def main():
1792+
...
17881793

1789-
asyncio.set_event_loop_policy(MyPolicy())
1794+
loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector())
1795+
asyncio.run(main(), loop_factory=loop_factory)
17901796

17911797

17921798
.. availability:: Unix, Windows.

‎Doc/library/asyncio-runner.rst

Copy file name to clipboardExpand all lines: Doc/library/asyncio-runner.rst
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Running an asyncio Program
7676

7777
*coro* can be any awaitable object.
7878

79+
.. note::
80+
81+
The :mod:`!asyncio` policy system is deprecated and will be removed
82+
in Python 3.16; from there on, an explicit *loop_factory* is needed
83+
to configure the event loop.
84+
7985

8086
Runner context manager
8187
======================

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.