Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62511fd

Browse files
committed
asyncio: document the debug mode
1 parent 1580fe3 commit 62511fd

3 files changed

Lines changed: 30 additions & 7 deletions

File tree

Doc/library/asyncio-dev.rst

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@ Asynchronous programming is different than classical "sequential" programming.
99
This 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

1437
Concurrency and multithreading
@@ -83,10 +106,10 @@ Detect coroutine objects never scheduled
83106
When 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

91114
The debug flag changes the behaviour of the :func:`coroutine` decorator. The
92115
debug flag value is only used when then coroutine function is defined, not when

Doc/library/asyncio-eventloop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ Debug mode
601601

602602
.. seealso::
603603

604-
The :ref:`Develop with asyncio <asyncio-dev>` section.
604+
The :ref:`debug mode of asyncio <asyncio-debug-mode>`.
605605

606606

607607
Server

Doc/using/cmdline.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ conflict.
616616

617617
.. envvar:: PYTHONASYNCIODEBUG
618618

619-
If this environment variable is set to a non-empty string, enable the debug
620-
mode of the :mod:`asyncio` module.
619+
If this environment variable is set to a non-empty string, enable the
620+
:ref:`debug mode <asyncio-debug-mode>` of the :mod:`asyncio` module.
621621

622622
.. versionadded:: 3.4
623623

0 commit comments

Comments
 (0)