From: Victor Stinner Date: Sun, 12 Oct 2014 19:37:16 +0000 (+0200) Subject: asyncio doc: update debug traces X-Git-Tag: v3.5.0a1~676^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ab1c85307948219ecf15608b7f7aad41fb8c8670;p=python asyncio doc: update debug traces --- diff --git a/Doc/library/asyncio-dev.rst b/Doc/library/asyncio-dev.rst index b797d6a78d..8ec2ff0914 100644 --- a/Doc/library/asyncio-dev.rst +++ b/Doc/library/asyncio-dev.rst @@ -166,26 +166,35 @@ Example of unhandled exception:: Output:: Task exception was never retrieved - future: + future: exception=Exception('not consumed',)> + Traceback (most recent call last): + File "asyncio/tasks.py", line 237, in _step + result = next(coro) + File "asyncio/coroutines.py", line 141, in coro + res = func(*args, **kw) + File "test.py", line 5, in bug + raise Exception("not consumed") + Exception: not consumed + +:ref:`Enable the debug mode of asyncio ` to get the +traceback where the task was created. Output in debug mode:: + + Task exception was never retrieved + future: exception=Exception('not consumed',) created at test.py:8> source_traceback: Object created at (most recent call last): - File "test.py", line 10, in + File "test.py", line 8, in asyncio.async(bug()) - File "asyncio/tasks.py", line 510, in async - task = loop.create_task(coro_or_future) Traceback (most recent call last): - File "asyncio/tasks.py", line 244, in _step + File "asyncio/tasks.py", line 237, in _step result = next(coro) - File "coroutines.py", line 78, in __next__ + File "asyncio/coroutines.py", line 79, in __next__ return next(self.gen) File "asyncio/coroutines.py", line 141, in coro res = func(*args, **kw) - File "test.py", line 7, in bug + File "test.py", line 5, in bug raise Exception("not consumed") Exception: not consumed -:ref:`Enable the debug mode of asyncio ` to get the -traceback where the task was created. - There are different options to fix this issue. The first option is to chain to coroutine in another coroutine and use classic try/except:: @@ -302,16 +311,18 @@ If a pending task is destroyed, the execution of its wrapped :ref:`coroutine Example of log:: + Task was destroyed but it is pending! + task: wait_for=> + +:ref:`Enable the debug mode of asyncio ` to get the +traceback where the task was created. Example of log in debug mode:: + Task was destroyed but it is pending! source_traceback: Object created at (most recent call last): - File "test.py", line 17, in + File "test.py", line 15, in task = asyncio.async(coro, loop=loop) - File "asyncio/tasks.py", line 510, in async - task = loop.create_task(coro_or_future) - task: > + task: wait_for= created at test.py:15> -:ref:`Enable the debug mode of asyncio ` to get the -traceback where the task was created. .. seealso::