Skip to content

[3.9] bpo-41696: Fix handling of debug mode in asyncio.run (GH-22069) #22071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
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`.