@@ -9,6 +9,29 @@ Asynchronous programming is different than classical "sequential" programming.
99This page lists common traps and explains how to avoid them.
1010
1111
12+ .. _asyncio-debug-mode :
13+
14+ Debug mode of asyncio
15+ ---------------------
16+
17+ To enable the debug mode globally, set the environment variable
18+ :envvar: `PYTHONASYNCIODEBUG ` to ``1 ``. Examples of effects of the debug mode:
19+
20+ * Log :ref: `coroutines defined but never "yielded from"
21+ <asyncio-coroutine-not-scheduled>`
22+ * :meth: `~BaseEventLoop.call_soon ` and :meth: `~BaseEventLoop.call_at ` methods
23+ raise an exception if they are called from the wrong thread.
24+ * Log the execution time of the selector
25+ * Log callbacks taking more than 100 ms to be executed. The
26+ :attr: `BaseEventLoop.slow_callback_duration ` attribute is the minimum
27+ duration in seconds of "slow" callbacks.
28+
29+ .. seealso ::
30+
31+ The :meth: `BaseEventLoop.set_debug ` method and the :ref: `asyncio logger
32+ <asyncio-logger>`.
33+
34+
1235.. _asyncio-multithreading :
1336
1437Concurrency and multithreading
@@ -83,10 +106,10 @@ Detect coroutine objects never scheduled
83106When a coroutine function is called but not passed to :func: `async ` or to the
84107:class: `Task ` constructor, it is not scheduled and it is probably a bug.
85108
86- To detect such bug, set the environment variable :envvar: ` PYTHONASYNCIODEBUG `
87- to `` 1 `` . When the coroutine object is destroyed by the garbage collector, a
88- log will be emitted with the traceback where the coroutine function was called.
89- See the :ref: `asyncio logger <asyncio-logger >`.
109+ To detect such bug, :ref: ` enable the debug mode of asyncio
110+ <asyncio-debug-mode>` . When the coroutine object is destroyed by the garbage
111+ collector, a log will be emitted with the traceback where the coroutine
112+ function was called. See the :ref: `asyncio logger <asyncio-logger >`.
90113
91114The debug flag changes the behaviour of the :func: `coroutine ` decorator. The
92115debug flag value is only used when then coroutine function is defined, not when
0 commit comments