]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41696: Fix handling of debug mode in asyncio.run (GH-22069) (#22072)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 3 Sep 2020 20:54:06 +0000 (13:54 -0700)
committerGitHub <noreply@github.com>
Thu, 3 Sep 2020 20:54:06 +0000 (13:54 -0700)
* 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 0770ad948cb6d9f7f6c4002efd83e27c27069808)

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Lib/asyncio/runners.py
Lib/test/test_asyncio/test_runners.py
Misc/NEWS.d/next/Library/2020-09-03-01-35-32.bpo-41696.zkYGre.rst [new file with mode: 0644]

index 2e37e18b45fc150536f6deedfc388c30e8aa6410..d2fa8b7f13861c5eedbb2cdea2845f6246cc2435 100644 (file)
@@ -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,7 +39,8 @@ def run(main, *, debug=False):
     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:
index 3b58ddee443adf68c1faeb9c839bd165b1f5bd7c..b9ae02dc3c04e096f17f90a7ba741b8714b7793d 100644 (file)
@@ -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():
diff --git a/Misc/NEWS.d/next/Library/2020-09-03-01-35-32.bpo-41696.zkYGre.rst b/Misc/NEWS.d/next/Library/2020-09-03-01-35-32.bpo-41696.zkYGre.rst
new file mode 100644 (file)
index 0000000..67bbbb8
--- /dev/null
@@ -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`.
\ No newline at end of file