Skip to content

Commit 0a7d435

Browse files
gh-96377: Update asyncio policy doc intro paras to be clear and accurate (GH-97603)
Also fix up some cross-references in the asyncio docs. (cherry picked from commit cc0f3a1) Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent dc0a87d commit 0a7d435

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

Doc/library/asyncio-dev.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ that the event loop runs in.
109109

110110
There is currently no way to schedule coroutines or callbacks directly
111111
from a different process (such as one started with
112-
:mod:`multiprocessing`). The :ref:`Event Loop Methods <asyncio-event-loop>`
112+
:mod:`multiprocessing`). The :ref:`asyncio-event-loop-methods`
113113
section lists APIs that can read from pipes and watch file descriptors
114114
without blocking the event loop. In addition, asyncio's
115115
:ref:`Subprocess <asyncio-subprocess>` APIs provide a way to start a

Doc/library/asyncio-eventloop.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.. currentmodule:: asyncio
22

33

4+
.. _asyncio-event-loop:
5+
46
==========
57
Event Loop
68
==========
@@ -92,7 +94,7 @@ This documentation page contains the following sections:
9294
loop APIs.
9395

9496

95-
.. _asyncio-event-loop:
97+
.. _asyncio-event-loop-methods:
9698

9799
Event Loop Methods
98100
==================
@@ -1498,6 +1500,7 @@ Do not instantiate the class directly.
14981500

14991501

15001502
.. _asyncio-event-loops:
1503+
.. _asyncio-event-loop-implementations:
15011504

15021505
Event Loop Implementations
15031506
==========================
@@ -1544,7 +1547,7 @@ on Unix and :class:`ProactorEventLoop` on Windows.
15441547

15451548
Abstract base class for asyncio-compliant event loops.
15461549

1547-
The :ref:`Event Loop Methods <asyncio-event-loop>` section lists all
1550+
The :ref:`asyncio-event-loop-methods` section lists all
15481551
methods that an alternative implementation of ``AbstractEventLoop``
15491552
should have defined.
15501553

Doc/library/asyncio-llapi-index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Event Loop Methods
3737
==================
3838

3939
See also the main documentation section about the
40-
:ref:`event loop methods <asyncio-event-loop>`.
40+
:ref:`asyncio-event-loop-methods`.
4141

4242
.. rubric:: Lifecycle
4343
.. list-table::

Doc/library/asyncio-policy.rst

+25-11
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,29 @@
77
Policies
88
========
99

10-
An event loop policy is a global per-process object that controls
11-
the management of the event loop. Each event loop has a default
12-
policy, which can be changed and customized using the policy API.
13-
14-
A policy defines the notion of *context* and manages a
15-
separate event loop per context. The default policy
16-
defines *context* to be the current thread.
17-
18-
By using a custom event loop policy, the behavior of
19-
:func:`get_event_loop`, :func:`set_event_loop`, and
20-
:func:`new_event_loop` functions can be customized.
10+
An event loop policy is a global (per-interpreter) object
11+
used to get and set the current :ref:`event loop <asyncio-event-loop>`,
12+
as well as create new event loops.
13+
The default policy can be :ref:`replaced <asyncio-policy-get-set>` with
14+
:ref:`built-in alternatives <asyncio-policy-builtin>`
15+
to use different event loop implementations,
16+
or substituted by a :ref:`custom policy <asyncio-custom-policies>`
17+
that can override these behaviors.
18+
19+
The :ref:`policy object <asyncio-policy-objects>`
20+
gets and sets a separate event loop per *context*.
21+
This is per-thread by default,
22+
though custom policies could define *context* differently.
23+
24+
Custom event loop policies can control the behavior of
25+
:func:`get_event_loop`, :func:`set_event_loop`, and :func:`new_event_loop`.
2126

2227
Policy objects should implement the APIs defined
2328
in the :class:`AbstractEventLoopPolicy` abstract base class.
2429

2530

31+
.. _asyncio-policy-get-set:
32+
2633
Getting and Setting the Policy
2734
==============================
2835

@@ -40,6 +47,8 @@ for the current process:
4047
If *policy* is set to ``None``, the default policy is restored.
4148

4249

50+
.. _asyncio-policy-objects:
51+
4352
Policy Objects
4453
==============
4554

@@ -86,6 +95,8 @@ The abstract event loop policy base class is defined as follows:
8695
This function is Unix specific.
8796

8897

98+
.. _asyncio-policy-builtin:
99+
89100
asyncio ships with the following built-in policies:
90101

91102

@@ -117,6 +128,7 @@ asyncio ships with the following built-in policies:
117128

118129
.. availability:: Windows.
119130

131+
120132
.. _asyncio-watchers:
121133

122134
Process Watchers
@@ -270,6 +282,8 @@ implementation used by the asyncio event loop:
270282
.. versionadded:: 3.9
271283

272284

285+
.. _asyncio-custom-policies:
286+
273287
Custom Policies
274288
===============
275289

0 commit comments

Comments
 (0)