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
@@ -160,7 +161,8 @@ def capture_call_graph(
160161
161162 call_stack : list [FrameCallGraphEntry ] = []
162163
163- f = sys ._getframe (depth ) if limit != 0 else None
164+ # gh-161124: find the task boundary before skipping frames
165+ f = sys ._getframe (0 ) if limit != 0 else None
164166 try :
165167 while f is not None :
166168 # gh-156988: sync gen should not clear the call chain
@@ -178,6 +180,8 @@ def capture_call_graph(
178180 finally :
179181 del f
180182
183+ call_stack = call_stack [max (0 , operator .index (depth )):]
184+
181185 awaited_by = []
182186 if future ._asyncio_awaited_by :
183187 for parent in future ._asyncio_awaited_by :
Original file line number Diff line number Diff line change @@ -785,6 +785,11 @@ async def main():
785785
786786 self .assertTrue (stack_for_fut [1 ].startswith ('* Future(id=' ))
787787
788+ async def test_call_graph_depth_beyond_task (self ):
789+ # gh-161124
790+ graph = asyncio .capture_call_graph (depth = 2 )
791+ self .assertEqual (graph .call_stack , ())
792+
788793 async def test_capture_call_graph_positive_limit (self ):
789794 captured = None
790795
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