7
7
Policies
8
8
========
9
9
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 `.
21
26
22
27
Policy objects should implement the APIs defined
23
28
in the :class: `AbstractEventLoopPolicy ` abstract base class.
24
29
25
30
31
+ .. _asyncio-policy-get-set :
32
+
26
33
Getting and Setting the Policy
27
34
==============================
28
35
@@ -40,6 +47,8 @@ for the current process:
40
47
If *policy * is set to ``None ``, the default policy is restored.
41
48
42
49
50
+ .. _asyncio-policy-objects :
51
+
43
52
Policy Objects
44
53
==============
45
54
@@ -86,6 +95,8 @@ The abstract event loop policy base class is defined as follows:
86
95
This function is Unix specific.
87
96
88
97
98
+ .. _asyncio-policy-builtin :
99
+
89
100
asyncio ships with the following built-in policies:
90
101
91
102
@@ -117,6 +128,7 @@ asyncio ships with the following built-in policies:
117
128
118
129
.. availability :: Windows.
119
130
131
+
120
132
.. _asyncio-watchers :
121
133
122
134
Process Watchers
@@ -270,6 +282,8 @@ implementation used by the asyncio event loop:
270
282
.. versionadded :: 3.9
271
283
272
284
285
+ .. _asyncio-custom-policies :
286
+
273
287
Custom Policies
274
288
===============
275
289
0 commit comments