File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -2124,11 +2124,21 @@ def test_collect_interrupted():
21242124 interrupt_error = None
21252125 main_thread = threading .main_thread ()
21262126
2127+ # Shared flag to indicate query execution has started
2128+ query_started = threading .Event ()
2129+ max_wait_time = 5.0 # Maximum wait time in seconds
2130+
21272131 # This function will be run in a separate thread and will raise
21282132 # KeyboardInterrupt in the main thread
21292133 def trigger_interrupt ():
2130- """Wait a moment then raise KeyboardInterrupt in the main thread"""
2131- time .sleep (0.5 ) # Give the query time to start
2134+ """Poll for query start, then raise KeyboardInterrupt in the main thread"""
2135+ # Poll for query to start with small sleep intervals
2136+ start_time = time .time ()
2137+ while not query_started .is_set ():
2138+ time .sleep (0.1 ) # Small sleep between checks
2139+ if time .time () - start_time > max_wait_time :
2140+ msg = f"Query did not start within { max_wait_time } seconds"
2141+ raise RuntimeError (msg )
21322142
21332143 # Check if thread ID is available
21342144 thread_id = main_thread .ident
@@ -2155,6 +2165,8 @@ def trigger_interrupt():
21552165
21562166 # Execute the query and expect it to be interrupted
21572167 try :
2168+ # Signal that we're about to start the query
2169+ query_started .set ()
21582170 df .collect ()
21592171 except KeyboardInterrupt :
21602172 interrupted = True
You can’t perform that action at this time.
0 commit comments