File tree 3 files changed +43
-6
lines changed
3 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -19,10 +19,35 @@ Pending removal in Python 3.16
19
19
* :mod: `asyncio `:
20
20
21
21
* :func: `!asyncio.iscoroutinefunction ` is deprecated
22
- and will be removed in Python 3.16,
22
+ and will be removed in Python 3.16;
23
23
use :func: `inspect.iscoroutinefunction ` instead.
24
24
(Contributed by Jiahao Li and Kumar Aditya in :gh: `122875 `.)
25
25
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
+
26
51
* :mod: `builtins `:
27
52
28
53
* Bitwise inversion on boolean types, ``~True `` or ``~False ``
Original file line number Diff line number Diff line change @@ -62,6 +62,13 @@ an event loop:
62
62
.. versionchanged :: 3.14
63
63
Raises a :exc: `RuntimeError ` if there is no current event loop.
64
64
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
+
65
72
.. function :: set_event_loop(loop)
66
73
67
74
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`.
1781
1788
import asyncio
1782
1789
import selectors
1783
1790
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
+ ...
1788
1793
1789
- asyncio.set_event_loop_policy(MyPolicy())
1794
+ loop_factory = lambda: asyncio.SelectorEventLoop(selectors.SelectSelector())
1795
+ asyncio.run(main(), loop_factory=loop_factory)
1790
1796
1791
1797
1792
1798
.. availability :: Unix, Windows.
Original file line number Diff line number Diff line change @@ -76,6 +76,12 @@ Running an asyncio Program
76
76
77
77
*coro * can be any awaitable object.
78
78
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
+
79
85
80
86
Runner context manager
81
87
======================
You can’t perform that action at this time.
0 commit comments