Skip to content
Merged
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
3 changes: 2 additions & 1 deletion Lib/asyncio/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,5 @@ def print_call_graph(
limit: int | None = None,
) -> None:
"""Print the async call graph for the current task or the provided Future."""
print(format_call_graph(future, depth=depth, limit=limit), file=file)
# gh-156327: print_call_graph() must not report its own frame
print(format_call_graph(future, depth=depth + 1, limit=limit), file=file)
10 changes: 9 additions & 1 deletion Lib/test/test_asyncio/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def walk(s):
return ret

buf = io.StringIO()
asyncio.print_call_graph(fut, file=buf, depth=depth+1)
asyncio.print_call_graph(fut, file=buf, depth=depth)

stack = asyncio.capture_call_graph(fut, depth=depth)
return walk(stack), buf.getvalue()
Expand Down Expand Up @@ -484,6 +484,14 @@ def test_capture_call_graph_non_future(self):
with self.assertRaises(TypeError):
asyncio.capture_call_graph("not a future")

async def test_print_call_graph_innermost_frame(self):
# gh-156327: print_call_graph() must not report its own frame
buf = io.StringIO()
lineno = sys._getframe().f_lineno + 1
asyncio.print_call_graph(file=buf)
first_frame = buf.getvalue().splitlines()[2]
self.assertIn(f'File {__file__!r}, line {lineno},', first_frame)

async def test_call_graph_finished_task(self):
# gh-156408: the call graph must not record a finished coroutine's None frame
async def boom():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`asyncio.print_call_graph` including its own frame in the printed
call stack.
Loading