|
5 | 5 | import sys |
6 | 6 | import socket |
7 | 7 | import threading |
| 8 | +import time |
8 | 9 | from asyncio import staggered, taskgroups, base_events, tasks |
9 | 10 | from unittest.mock import ANY |
10 | 11 | from test.support import os_helper, SHORT_TIMEOUT, busy_retry, requires_gil_enabled |
@@ -930,9 +931,6 @@ def main_work(): |
930 | 931 | # Signal threads to start waiting |
931 | 932 | ready_event.set() |
932 | 933 |
|
933 | | - # Give threads time to start sleeping |
934 | | - time.sleep(0.1) |
935 | | -
|
936 | 934 | # Now do busy work to hold the GIL |
937 | 935 | main_work() |
938 | 936 | """ |
@@ -967,7 +965,23 @@ def main_work(): |
967 | 965 |
|
968 | 966 | # Get stack trace with all threads |
969 | 967 | unwinder_all = RemoteUnwinder(p.pid, all_threads=True) |
970 | | - all_traces = unwinder_all.get_stack_trace() |
| 968 | + for _ in range(10): |
| 969 | + # Wait for the main thread to start its busy work |
| 970 | + all_traces = unwinder_all.get_stack_trace() |
| 971 | + found = False |
| 972 | + for thread_id, stack in all_traces: |
| 973 | + if not stack: |
| 974 | + continue |
| 975 | + current_frame = stack[0] |
| 976 | + if current_frame.funcname == "main_work" and current_frame.lineno >15: |
| 977 | + found = True |
| 978 | + |
| 979 | + if found: |
| 980 | + break |
| 981 | + # Give a bit of time to take the next sample |
| 982 | + time.sleep(0.1) |
| 983 | + else: |
| 984 | + self.fail("Main thread did not start its busy work on time") |
971 | 985 |
|
972 | 986 | # Get stack trace with only GIL holder |
973 | 987 | unwinder_gil = RemoteUnwinder(p.pid, only_active_thread=True) |
|
0 commit comments