Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab1c853

Browse files
committed
asyncio doc: update debug traces
1 parent 980dd84 commit ab1c853

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

Doc/library/asyncio-dev.rst

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,35 @@ Example of unhandled exception::
166166
Output::
167167

168168
Task exception was never retrieved
169-
future: <Task finished bug() done at asyncio/coroutines.py:139 exception=Exception('not consumed',)>
169+
future: <Task finished coro=<coro() done, defined at asyncio/coroutines.py:139> exception=Exception('not consumed',)>
170+
Traceback (most recent call last):
171+
File "asyncio/tasks.py", line 237, in _step
172+
result = next(coro)
173+
File "asyncio/coroutines.py", line 141, in coro
174+
res = func(*args, **kw)
175+
File "test.py", line 5, in bug
176+
raise Exception("not consumed")
177+
Exception: not consumed
178+
179+
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the
180+
traceback where the task was created. Output in debug mode::
181+
182+
Task exception was never retrieved
183+
future: <Task finished coro=<bug() done, defined at test.py:3> exception=Exception('not consumed',) created at test.py:8>
170184
source_traceback: Object created at (most recent call last):
171-
File "test.py", line 10, in <module>
185+
File "test.py", line 8, in <module>
172186
asyncio.async(bug())
173-
File "asyncio/tasks.py", line 510, in async
174-
task = loop.create_task(coro_or_future)
175187
Traceback (most recent call last):
176-
File "asyncio/tasks.py", line 244, in _step
188+
File "asyncio/tasks.py", line 237, in _step
177189
result = next(coro)
178-
File "coroutines.py", line 78, in __next__
190+
File "asyncio/coroutines.py", line 79, in __next__
179191
return next(self.gen)
180192
File "asyncio/coroutines.py", line 141, in coro
181193
res = func(*args, **kw)
182-
File "test.py", line 7, in bug
194+
File "test.py", line 5, in bug
183195
raise Exception("not consumed")
184196
Exception: not consumed
185197

186-
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the
187-
traceback where the task was created.
188-
189198
There are different options to fix this issue. The first option is to chain to
190199
coroutine in another coroutine and use classic try/except::
191200

@@ -302,16 +311,18 @@ If a pending task is destroyed, the execution of its wrapped :ref:`coroutine
302311

303312
Example of log::
304313

314+
Task was destroyed but it is pending!
315+
task: <Task pending coro=<kill_me() done, defined at test.py:5> wait_for=<Future pending cb=[Task._wakeup()]>>
316+
317+
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the
318+
traceback where the task was created. Example of log in debug mode::
319+
305320
Task was destroyed but it is pending!
306321
source_traceback: Object created at (most recent call last):
307-
File "test.py", line 17, in <module>
322+
File "test.py", line 15, in <module>
308323
task = asyncio.async(coro, loop=loop)
309-
File "asyncio/tasks.py", line 510, in async
310-
task = loop.create_task(coro_or_future)
311-
task: <Task pending kill_me() done at test.py:5 wait_for=<Future pending cb=[Task._wakeup()]>>
324+
task: <Task pending coro=<kill_me() done, defined at test.py:5> wait_for=<Future pending cb=[Task._wakeup()] created at test.py:7> created at test.py:15>
312325

313-
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the
314-
traceback where the task was created.
315326

316327
.. seealso::
317328

0 commit comments

Comments
 (0)