@@ -140,15 +140,27 @@ def foo():
140140 ]
141141 # Is possible that there are more threads, so we check that the
142142 # expected stack traces are in the result (looking at you Windows!)
143- self .assertIn ((ANY , thread_expected_stack_trace ), stack_trace )
143+ found_expected_stack = False
144+ for interpreter_info in stack_trace :
145+ for thread_info in interpreter_info .threads :
146+ if thread_info .frame_info == thread_expected_stack_trace :
147+ found_expected_stack = True
148+ break
149+ if found_expected_stack :
150+ break
151+ self .assertTrue (found_expected_stack , "Expected thread stack trace not found" )
144152
145153 # Check that the main thread stack trace is in the result
146154 frame = FrameInfo ([script_name , 19 , "<module>" ])
147- for _ , stack in stack_trace :
148- if frame in stack :
155+ main_thread_found = False
156+ for interpreter_info in stack_trace :
157+ for thread_info in interpreter_info .threads :
158+ if frame in thread_info .frame_info :
159+ main_thread_found = True
160+ break
161+ if main_thread_found :
149162 break
150- else :
151- self .fail ("Main thread stack trace not found in result" )
163+ self .assertTrue (main_thread_found , "Main thread stack trace not found in result" )
152164
153165 @skip_if_not_supported
154166 @unittest .skipIf (
@@ -1086,13 +1098,17 @@ def test_self_trace(self):
10861098 # Is possible that there are more threads, so we check that the
10871099 # expected stack traces are in the result (looking at you Windows!)
10881100 this_tread_stack = None
1089- for thread_id , stack in stack_trace :
1090- if thread_id == threading .get_native_id ():
1091- this_tread_stack = stack
1101+ # New format: [InterpreterInfo(interpreter_id, [ThreadInfo(...)])]
1102+ for interpreter_info in stack_trace :
1103+ for thread_info in interpreter_info .threads :
1104+ if thread_info .thread_id == threading .get_native_id ():
1105+ this_tread_stack = thread_info .frame_info
1106+ break
1107+ if this_tread_stack :
10921108 break
10931109 self .assertIsNotNone (this_tread_stack )
10941110 self .assertEqual (
1095- stack [:2 ],
1111+ this_tread_stack [:2 ],
10961112 [
10971113 FrameInfo (
10981114 [
@@ -1203,15 +1219,20 @@ def main_work():
12031219 # Wait for the main thread to start its busy work
12041220 all_traces = unwinder_all .get_stack_trace ()
12051221 found = False
1206- for thread_id , stack in all_traces :
1207- if not stack :
1208- continue
1209- current_frame = stack [0 ]
1210- if (
1211- current_frame .funcname == "main_work"
1212- and current_frame .lineno > 15
1213- ):
1214- found = True
1222+ # New format: [InterpreterInfo(interpreter_id, [ThreadInfo(...)])]
1223+ for interpreter_info in all_traces :
1224+ for thread_info in interpreter_info .threads :
1225+ if not thread_info .frame_info :
1226+ continue
1227+ current_frame = thread_info .frame_info [0 ]
1228+ if (
1229+ current_frame .funcname == "main_work"
1230+ and current_frame .lineno > 15
1231+ ):
1232+ found = True
1233+ break
1234+ if found :
1235+ break
12151236
12161237 if found :
12171238 break
@@ -1237,19 +1258,31 @@ def main_work():
12371258 p .terminate ()
12381259 p .wait (timeout = SHORT_TIMEOUT )
12391260
1240- # Verify we got multiple threads in all_traces
1261+ # Count total threads across all interpreters in all_traces
1262+ total_threads = sum (len (interpreter_info .threads ) for interpreter_info in all_traces )
12411263 self .assertGreater (
1242- len ( all_traces ) , 1 , "Should have multiple threads"
1264+ total_threads , 1 , "Should have multiple threads"
12431265 )
12441266
1245- # Verify we got exactly one thread in gil_traces
1267+ # Count total threads across all interpreters in gil_traces
1268+ total_gil_threads = sum (len (interpreter_info .threads ) for interpreter_info in gil_traces )
12461269 self .assertEqual (
1247- len ( gil_traces ) , 1 , "Should have exactly one GIL holder"
1270+ total_gil_threads , 1 , "Should have exactly one GIL holder"
12481271 )
12491272
1250- # The GIL holder should be in the all_traces list
1251- gil_thread_id = gil_traces [0 ][0 ]
1252- all_thread_ids = [trace [0 ] for trace in all_traces ]
1273+ # Get the GIL holder thread ID
1274+ gil_thread_id = None
1275+ for interpreter_info in gil_traces :
1276+ if interpreter_info .threads :
1277+ gil_thread_id = interpreter_info .threads [0 ].thread_id
1278+ break
1279+
1280+ # Get all thread IDs from all_traces
1281+ all_thread_ids = []
1282+ for interpreter_info in all_traces :
1283+ for thread_info in interpreter_info .threads :
1284+ all_thread_ids .append (thread_info .thread_id )
1285+
12531286 self .assertIn (
12541287 gil_thread_id ,
12551288 all_thread_ids ,
0 commit comments