Skip to content

Commit 90729cb

Browse files
remove asyncio policy system
1 parent 18281db commit 90729cb

62 files changed

Lines changed: 245 additions & 694 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,6 @@ Pending removal 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-
36-
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
37-
*loop_factory* to use the desired event loop implementation.
38-
39-
For example, to use :class:`asyncio.SelectorEventLoop` on Windows::
40-
41-
import asyncio
42-
43-
async def main():
44-
...
45-
46-
asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
47-
48-
(Contributed by Kumar Aditya in :gh:`127949`.)
49-
5026
* :mod:`builtins`:
5127

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

Doc/library/asyncio-eventloop.rst

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ an event loop:
4848
running event loop.
4949

5050
If there is no running event loop set, the function will return
51-
the result of the ``get_event_loop_policy().get_event_loop()`` call.
51+
the loop set by :func:`set_event_loop`, or raise a :exc:`RuntimeError`
52+
if no loop has been set.
5253

53-
Because this function has rather complex behavior (especially
54-
when custom event loop policies are in use), using the
54+
Because this function has rather complex behavior, using the
5555
:func:`get_running_loop` function is preferred to :func:`get_event_loop`
5656
in coroutines and callbacks.
5757

@@ -62,13 +62,6 @@ 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 return the current
69-
running event loop if present else it will return the
70-
loop set by :func:`set_event_loop`.
71-
7265
.. function:: set_event_loop(loop)
7366

7467
Set *loop* as the current event loop for the current OS thread.
@@ -77,10 +70,6 @@ an event loop:
7770

7871
Create and return a new event loop object.
7972

80-
Note that the behaviour of :func:`get_event_loop`, :func:`set_event_loop`,
81-
and :func:`new_event_loop` functions can be altered by
82-
:ref:`setting a custom event loop policy <asyncio-policies>`.
83-
8473

8574
.. rubric:: Contents
8675

Doc/library/asyncio-llapi-index.rst

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -497,27 +497,3 @@ Protocol classes can implement the following **callback methods**:
497497
- Called when the child process has exited. It can be called before
498498
:meth:`~SubprocessProtocol.pipe_data_received` and
499499
:meth:`~SubprocessProtocol.pipe_connection_lost` methods.
500-
501-
502-
Event Loop Policies
503-
===================
504-
505-
Policies is a low-level mechanism to alter the behavior of
506-
functions like :func:`asyncio.get_event_loop`. See also
507-
the main :ref:`policies section <asyncio-policies>` for more
508-
details.
509-
510-
511-
.. rubric:: Accessing Policies
512-
.. list-table::
513-
:widths: 50 50
514-
:class: full-width-table
515-
516-
* - :meth:`asyncio.get_event_loop_policy`
517-
- Return the current process-wide policy.
518-
519-
* - :meth:`asyncio.set_event_loop_policy`
520-
- Set a new process-wide policy.
521-
522-
* - :class:`AbstractEventLoopPolicy`
523-
- Base class for policy objects.

Doc/library/asyncio-policy.rst

Lines changed: 0 additions & 173 deletions
This file was deleted.

Doc/library/asyncio-runner.rst

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ Running an asyncio Program
4343
otherwise :func:`asyncio.new_event_loop` is used. The loop is closed at the end.
4444
This function should be used as a main entry point for asyncio programs,
4545
and should ideally only be called once. It is recommended to use
46-
*loop_factory* to configure the event loop instead of policies.
47-
Passing :class:`asyncio.EventLoop` allows running asyncio without the
48-
policy system.
46+
*loop_factory* to configure the event loop.
4947

5048
The executor is given a timeout duration of 5 minutes to shutdown.
5149
If the executor hasn't finished within that duration, a warning is
@@ -76,12 +74,6 @@ Running an asyncio Program
7674

7775
*coro* can be any awaitable object.
7876

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-
8577

8678
Runner context manager
8779
======================

Doc/library/asyncio.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ for full functionality and the latest features.
117117
asyncio-eventloop.rst
118118
asyncio-future.rst
119119
asyncio-protocol.rst
120-
asyncio-policy.rst
121120
asyncio-platforms.rst
122121
asyncio-extending.rst
123122

Doc/whatsnew/3.14.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,12 +2628,12 @@ New deprecations
26282628
and will be removed in Python 3.16.
26292629
In particular, the following classes and functions are deprecated:
26302630

2631-
* :class:`asyncio.AbstractEventLoopPolicy`
2632-
* :class:`asyncio.DefaultEventLoopPolicy`
2633-
* :class:`asyncio.WindowsSelectorEventLoopPolicy`
2634-
* :class:`asyncio.WindowsProactorEventLoopPolicy`
2635-
* :func:`asyncio.get_event_loop_policy`
2636-
* :func:`asyncio.set_event_loop_policy`
2631+
* :class:`!asyncio.AbstractEventLoopPolicy`
2632+
* :class:`!asyncio.DefaultEventLoopPolicy`
2633+
* :class:`!asyncio.WindowsSelectorEventLoopPolicy`
2634+
* :class:`!asyncio.WindowsProactorEventLoopPolicy`
2635+
* :func:`!asyncio.get_event_loop_policy`
2636+
* :func:`!asyncio.set_event_loop_policy`
26372637

26382638
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
26392639
the *loop_factory* argument to use the desired event loop implementation.

Doc/whatsnew/3.16.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ asyncio
121121
which has been deprecated since Python 3.14.
122122
Use :func:`inspect.iscoroutinefunction` instead.
123123

124+
* The event loop policy system, including the
125+
:class:`!asyncio.AbstractEventLoopPolicy`,
126+
:class:`!asyncio.DefaultEventLoopPolicy`,
127+
:class:`!asyncio.WindowsSelectorEventLoopPolicy` and
128+
:class:`!asyncio.WindowsProactorEventLoopPolicy` classes and the
129+
:func:`!asyncio.get_event_loop_policy` and
130+
:func:`!asyncio.set_event_loop_policy` functions,
131+
which have been deprecated since Python 3.14.
132+
Use :func:`asyncio.run` or :class:`asyncio.Runner` with a custom
133+
*loop_factory* instead.
134+
124135
functools
125136
---------
126137

Lib/asyncio/__init__.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,3 @@
4747
else:
4848
from .unix_events import * # pragma: no cover
4949
__all__ += unix_events.__all__
50-
51-
def __getattr__(name: str):
52-
import warnings
53-
54-
match name:
55-
case "AbstractEventLoopPolicy":
56-
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
57-
return events._AbstractEventLoopPolicy
58-
case "DefaultEventLoopPolicy":
59-
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
60-
if sys.platform == 'win32':
61-
return windows_events._DefaultEventLoopPolicy
62-
return unix_events._DefaultEventLoopPolicy
63-
case "WindowsSelectorEventLoopPolicy":
64-
if sys.platform == 'win32':
65-
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
66-
return windows_events._WindowsSelectorEventLoopPolicy
67-
# Else fall through to the AttributeError below.
68-
case "WindowsProactorEventLoopPolicy":
69-
if sys.platform == 'win32':
70-
warnings._deprecated(f"asyncio.{name}", remove=(3, 16))
71-
return windows_events._WindowsProactorEventLoopPolicy
72-
# Else fall through to the AttributeError below.
73-
74-
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

0 commit comments

Comments
 (0)