File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import dataclasses
44import io
5+ import operator
56import sys
67import types
78
@@ -152,7 +153,8 @@ def capture_call_graph(
152153
153154 call_stack : list [FrameCallGraphEntry ] = []
154155
155- f = sys ._getframe (depth ) if limit != 0 else None
156+ # gh-161124: find the task boundary before skipping frames
157+ f = sys ._getframe (0 ) if limit != 0 else None
156158 try :
157159 while f is not None :
158160 # gh-156988: sync gen should not clear the call chain
@@ -170,6 +172,8 @@ def capture_call_graph(
170172 finally :
171173 del f
172174
175+ call_stack = call_stack [max (0 , operator .index (depth )):]
176+
173177 awaited_by = []
174178 if future ._asyncio_awaited_by :
175179 for parent in future ._asyncio_awaited_by :
Original file line number Diff line number Diff line change @@ -457,6 +457,11 @@ async def main():
457457
458458 self .assertTrue (stack_for_fut [1 ].startswith ('* Future(id=' ))
459459
460+ async def test_call_graph_depth_beyond_task (self ):
461+ # gh-161124
462+ graph = asyncio .capture_call_graph (depth = 2 )
463+ self .assertEqual (graph .call_stack , ())
464+
460465 async def test_call_graph_finished_task (self ):
461466 # gh-156408: the call graph must not record a finished coroutine's None frame
462467 async def boom ():
Original file line number Diff line number Diff line change 1+ Fix :func: `asyncio.print_call_graph ` reporting event loop frames when
2+ *depth * exceeds the task stack. Patch by Timofei Ivankov.
You can’t perform that action at this time.
0 commit comments