Skip to content

Commit 5073070

Browse files
committed
Revert "."
This reverts commit b8ce3e4.
1 parent b8ce3e4 commit 5073070

File tree

1 file changed

+11
-36
lines changed

1 file changed

+11
-36
lines changed

python/tests/test_dataframe.py

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,24 +2124,11 @@ def test_collect_interrupted():
21242124
interrupt_error = None
21252125
main_thread = threading.main_thread()
21262126

2127-
# Flag to indicate when query execution has started
2128-
query_started = False
2129-
21302127
# This function will be run in a separate thread and will raise
21312128
# KeyboardInterrupt in the main thread
21322129
def trigger_interrupt():
2133-
"""Poll until query starts, then raise KeyboardInterrupt in the main thread"""
2134-
# Poll until the query has started or timeout reached
2135-
timeout = 5 # Maximum wait time in seconds
2136-
start_time = time.time()
2137-
2138-
while not query_started:
2139-
time.sleep(0.1) # Short sleep between checks
2140-
if time.time() - start_time > timeout:
2141-
msg = "Timeout waiting for query to start"
2142-
raise RuntimeError(msg)
2143-
2144-
# At this point, query has started, so we can interrupt it
2130+
"""Wait a moment then raise KeyboardInterrupt in the main thread"""
2131+
time.sleep(0.5) # Give the query time to start
21452132

21462133
# Check if thread ID is available
21472134
thread_id = main_thread.ident
@@ -2155,32 +2142,20 @@ def trigger_interrupt():
21552142
ctypes.c_long(thread_id), exception)
21562143
if res != 1:
21572144
# If res is 0, the thread ID was invalid
2158-
raise RuntimeError("Invalid thread ID") > 1, we modified multiple threads
2159-
elif res > 1:PyThreadState_SetAsyncExc(
2160-
# If res > 1, there was an error raising the exceptionong(thread_id), ctypes.py_object(0))
2161-
raise RuntimeError("Failed to raise exception in the main thread")to raise KeyboardInterrupt in main thread"
2162-
ror(msg)
2145+
# If res > 1, we modified multiple threads
2146+
ctypes.pythonapi.PyThreadState_SetAsyncExc(
2147+
ctypes.c_long(thread_id), ctypes.py_object(0))
2148+
msg = "Failed to raise KeyboardInterrupt in main thread"
2149+
raise RuntimeError(msg)
2150+
21632151
# Start a thread to trigger the interrupt
21642152
interrupt_thread = threading.Thread(target=trigger_interrupt)
21652153
interrupt_thread.daemon = True
21662154
interrupt_thread.start()
2167-
interrupt_thread.start()
2155+
21682156
# Execute the query and expect it to be interrupted
2169-
try:to be interrupted
2170-
# Signal that the query is about to start try:
2171-
2172-
2173-
2174-
2175-
2176-
2177-
2178-
2179-
2180-
2181-
2182-
assert interrupt_error is None, f"Unexpected error occurred: {interrupt_error}" assert interrupted, "Query was not interrupted by KeyboardInterrupt" # Assert that the query was interrupted properly interrupt_error = e except Exception as e: interrupted = True except KeyboardInterrupt: df.collect() query_started = True df.collect()
2183-
query_started = True # Mark query as started
2157+
try:
2158+
df.collect()
21842159
except KeyboardInterrupt:
21852160
interrupted = True
21862161
except Exception as e:

0 commit comments

Comments
 (0)