Skip to content

Commit a268005

Browse files
bpo-41696: Fix handling of debug mode in asyncio.run (GH-22069) (#22071)
* bpo-41696: Fix handling of debug mode in asyncio.run This allows PYTHONASYNCIODEBUG or -X dev to enable asyncio debug mode when using asyncio.run * πŸ“œπŸ€– Added by blurb_it. Co-authored-by: hauntsaninja <> Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> (cherry picked from commit 0770ad9) Co-authored-by: Shantanu <[email protected]> Co-authored-by: Shantanu <[email protected]>
1 parent 49571c0 commit a268005

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

β€ŽLib/asyncio/runners.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from . import tasks
66

77

8-
def run(main, *, debug=False):
8+
def run(main, *, debug=None):
99
"""Execute the coroutine and return the result.
1010
1111
This function runs the passed coroutine, taking care of
@@ -39,7 +39,8 @@ async def main():
3939
loop = events.new_event_loop()
4040
try:
4141
events.set_event_loop(loop)
42-
loop.set_debug(debug)
42+
if debug is not None:
43+
loop.set_debug(debug)
4344
return loop.run_until_complete(main)
4445
finally:
4546
try:

β€ŽLib/test/test_asyncio/test_runners.py

+3
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ async def main(expected):
8787

8888
asyncio.run(main(False))
8989
asyncio.run(main(True), debug=True)
90+
with mock.patch('asyncio.coroutines._is_debug_mode', lambda: True):
91+
asyncio.run(main(True))
92+
asyncio.run(main(False), debug=False)
9093

9194
def test_asyncio_run_from_running_loop(self):
9295
async def main():
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix handling of debug mode in :func:`asyncio.run`. This allows setting ``PYTHONASYNCIODEBUG`` or ``-X dev`` to enable asyncio debug mode when using :func:`asyncio.run`.

0 commit comments

Comments
Β (0)