[3.15] gh-156988: Fix asyncio call graph loss at sync generators by deadlovelll · Pull Request #157004 · python/cpython · GitHub
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
4 changes: 3 additions & 1 deletion Lib/asyncio/graph.py
20 changes: 20 additions & 0 deletions Lib/test/test_asyncio/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,26 @@ 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_capture_call_graph_generator_keeps_caller_frames(self):
# gh-156988: sync gen should not clear the call chain
stack = None

def gen():
nonlocal stack
graph = asyncio.capture_call_graph()
stack = [entry.frame.f_code.co_name for entry in graph.call_stack]
yield

def middle():
for _ in gen():
pass

async def main():
middle()

await main()
self.assertEqual(stack[:3], ['gen', 'middle', 'main'])


@unittest.skipIf(
not hasattr(asyncio.futures, "_c_future_add_to_awaited_by"),
Expand Down
Loading