You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Doc/library/asyncio-dev.rst
+27-16Lines changed: 27 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -166,26 +166,35 @@ Example of unhandled exception::
166
166
Output::
167
167
168
168
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>
170
184
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>
172
186
asyncio.async(bug())
173
-
File "asyncio/tasks.py", line 510, in async
174
-
task = loop.create_task(coro_or_future)
175
187
Traceback (most recent call last):
176
-
File "asyncio/tasks.py", line 244, in _step
188
+
File "asyncio/tasks.py", line 237, in _step
177
189
result = next(coro)
178
-
File "coroutines.py", line 78, in __next__
190
+
File "asyncio/coroutines.py", line 79, in __next__
179
191
return next(self.gen)
180
192
File "asyncio/coroutines.py", line 141, in coro
181
193
res = func(*args, **kw)
182
-
File "test.py", line 7, in bug
194
+
File "test.py", line 5, in bug
183
195
raise Exception("not consumed")
184
196
Exception: not consumed
185
197
186
-
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the
187
-
traceback where the task was created.
188
-
189
198
There are different options to fix this issue. The first option is to chain to
190
199
coroutine in another coroutine and use classic try/except::
191
200
@@ -302,16 +311,18 @@ If a pending task is destroyed, the execution of its wrapped :ref:`coroutine
302
311
303
312
Example of log::
304
313
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
+
305
320
Task was destroyed but it is pending!
306
321
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>
308
323
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>
312
325
313
-
:ref:`Enable the debug mode of asyncio <asyncio-debug-mode>` to get the
0 commit comments