Skip to content

Commit

Permalink
bpo-41696: Fix handling of debug mode in asyncio.run (python#22069)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and Seth Sims committed Oct 18, 2020
1 parent de11d22 commit 17b3119
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
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
Original file line number Diff line number Diff line change
@@ -0,0 +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 comments on commit 17b3119

Please sign in to comment.