@@ -14,16 +14,22 @@ This page lists common traps and explains how to avoid them.
1414Debug mode of asyncio
1515---------------------
1616
17- To enable the debug mode globally, set the environment variable
18- :envvar: `PYTHONASYNCIODEBUG ` to ``1 ``. To see debug traces, set the log level
19- of the :ref: `asyncio logger <asyncio-logger >` to :py:data: `logging.DEBUG `. The
20- simplest configuration is::
17+ The implementation of :mod: `asyncio ` module has been written for performances.
18+ To development with asyncio, it's required to enable the debug checks to ease
19+ the development of asynchronous code.
2120
22- import logging
23- # ...
24- logging.basicConfig(level=logging.DEBUG)
21+ Setup an application to enable all debug checks:
2522
26- Examples of effects of the debug mode:
23+ * Enable the asyncio debug mode globally by setting the environment variable
24+ :envvar: `PYTHONASYNCIODEBUG ` to ``1 ``
25+ * Set the log level of the :ref: `asyncio logger <asyncio-logger >` to
26+ :py:data: `logging.DEBUG `. For example, call
27+ ``logging.basicConfig(level=logging.DEBUG) `` at startup.
28+ * Configure the :mod: `warnings ` module to display :exc: `ResourceWarning `
29+ warnings. For example, use the ``-Wdefault `` command line option of Python to
30+ display them.
31+
32+ Examples debug checks:
2733
2834* Log :ref: `coroutines defined but never "yielded from"
2935 <asyncio-coroutine-not-scheduled>`
@@ -33,6 +39,8 @@ Examples of effects of the debug mode:
3339* Log callbacks taking more than 100 ms to be executed. The
3440 :attr: `BaseEventLoop.slow_callback_duration ` attribute is the minimum
3541 duration in seconds of "slow" callbacks.
42+ * :exc: `ResourceWarning ` warnings are emitted when transports and event loops
43+ are :ref: `not closed explicitly <asyncio-close-transports >`.
3644
3745.. seealso ::
3846
@@ -372,14 +380,15 @@ traceback where the task was created. Example of log in debug mode::
372380
373381 :ref: `Detect coroutine objects never scheduled <asyncio-coroutine-not-scheduled >`.
374382
383+ .. _asyncio-close-transports :
375384
376- Close transports
377- ----------------
385+ Close transports and event loops
386+ --------------------------------
378387
379388When a transport is no more needed, call its ``close() `` method to release
380- resources.
389+ resources. Event loops must also be closed explicitly.
381390
382- If a transport ( or an event loop) is not closed explicitly, a
383- :exc: `ResourceWarning ` warning will be emitted in its destructor. The
384- :exc: `ResourceWarning ` warnings are hidden by default: use the `` -Wd `` command
385- line option of Python to show them.
391+ If a transport or an event loop is not closed explicitly, a
392+ :exc: `ResourceWarning ` warning will be emitted in its destructor. By default,
393+ :exc: `ResourceWarning ` warnings are ignored. The :ref: ` Debug mode of asyncio
394+ <asyncio-debug-mode>` section explains how to display them.
0 commit comments