This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: DEBUG kw to asyncio.run overrides DEBUG mode set elsewhere
Type: Stage: resolved
Components: asyncio Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, asvetlov, primal, yselivanov
Priority: normal Keywords: patch

Created on 2020-04-30 20:06 by primal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19895 closed ZackerySpytz, 2020-05-04 05:40
Messages (3)
msg367779 - (view) Author: Paul Martin (primal) * Date: 2020-04-30 20:06
According to the docs:

"
There are several ways to enable asyncio debug mode.

Setting the PYTHONASYNCIODEBUG environment variable to 1.
Using the -X dev Python command line option.
Passing debug=True to asyncio.run().
Calling loop.set_debug().
"

My understanding of this would be that any of the above methods can be used to enable debug mode. However if asyncio.run is used then whatever value for DEBUG is passed to asyncio.run (or False by default) overrides DEBUG mode being set elsewhere. So, when asyncio.run is used, the only way to enable DEBUG mode is to pass DEBUG=True to asyncio.run. The other methods won't work. 

One solution might be to change this line in asyncio/runners.py:

loop.set_debug(debug)

To

loop.set_debug(debug or coroutines._DEBUG)

So asyncio.run won't disable debug mode if it's already been set elsewhere
msg368094 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2020-05-04 23:52
Good catch. The function should be fixed to:

  _marker = object()

  def run(coro, *, debug=_marker):
     if debug is not _marker:
        loop.set_debug(debug)
msg415008 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-12 19:42
Fixed by #41696
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84634
2022-03-12 19:42:35asvetlovsetstatus: open -> closed
resolution: duplicate
messages: + msg415008

stage: patch review -> resolved
2020-05-04 23:52:58yselivanovsetmessages: + msg368094
2020-05-04 05:40:30ZackerySpytzsetkeywords: + patch
nosy: + ZackerySpytz

pull_requests: + pull_request19206
stage: patch review
2020-04-30 20:06:09primalcreate