Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
hauntsaninja committed Sep 3, 2020
commit 14ee79bf7c694186af75bd8be7a008d4269153c2
5 changes: 3 additions & 2 deletions Lib/asyncio/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from . import tasks


def run(main, *, debug=False):
def run(main, *, debug=None):
"""Execute the coroutine and return the result.

This function runs the passed coroutine, taking care of
Expand Down Expand Up @@ -39,7 +39,8 @@ async def main():
loop = events.new_event_loop()
try:
events.set_event_loop(loop)
loop.set_debug(debug)
if debug is not None:
loop.set_debug(debug)
return loop.run_until_complete(main)
finally:
try:
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_asyncio/test_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ async def main(expected):

asyncio.run(main(False))
asyncio.run(main(True), debug=True)
with mock.patch('asyncio.coroutines._is_debug_mode', lambda: True):
asyncio.run(main(True))
asyncio.run(main(False), debug=False)

def test_asyncio_run_from_running_loop(self):
async def main():
Expand Down