mirror of https://github.com/python/cpython
bpo-41696: Fix handling of debug mode in asyncio.run (#22069)
* 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>
This commit is contained in:
parent
4a97b1517a
commit
0770ad948c
|
@ -5,7 +5,7 @@ from . import events
|
|||
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
|
||||
|
@ -39,6 +39,7 @@ def run(main, *, debug=False):
|
|||
loop = events.new_event_loop()
|
||||
try:
|
||||
events.set_event_loop(loop)
|
||||
if debug is not None:
|
||||
loop.set_debug(debug)
|
||||
return loop.run_until_complete(main)
|
||||
finally:
|
||||
|
|
|
@ -87,6 +87,9 @@ class RunTests(BaseTest):
|
|||
|
||||
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():
|
||||
|
|
|
@ -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`.
|
Loading…
Reference in New Issue