Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/asyncio/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _build_graph_for_future(

coro = None
if get_coro := getattr(future, 'get_coro', None):
coro = get_coro() if limit != 0 else None
coro = get_coro() if limit != 0 and not future.done() else None

st: list[FrameCallGraphEntry] = []
awaited_by: list[FutureCallGraph] = []
Expand Down
22 changes: 22 additions & 0 deletions Lib/test/test_asyncio/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,28 @@ async def boom():
self.assertEqual(asyncio.capture_call_graph(task).call_stack, ())
self.assertIn(f"name={task.get_name()!r}", buf.getvalue())

async def test_call_graph_finished_anext_task(self):
# gh-162235
async def gen():
yield 1
await asyncio.sleep(0)
yield 2

agen = gen()
done = asyncio.create_task(anext(agen), name='done')
await done

other = asyncio.create_task(anext(agen), name='other')
await asyncio.sleep(0)
done_graph = asyncio.capture_call_graph(done)

await other
await agen.aclose()
other_graph = asyncio.capture_call_graph(other)

self.assertEqual(done_graph.call_stack, ())
self.assertEqual(other_graph.call_stack, ())

async def test_capture_call_graph_no_current_task(self):
results = []

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :func:`asyncio.print_call_graph` showing incorrect stacks or raising
:exc:`AttributeError` for finished :func:`anext` tasks. Patch by Timofey
Ivankov.
Loading