Skip to content

Commit 12912c6

Browse files
tools: enable ctrl-c for parallel tests
use a threading.Event instead of a boolean attribute. PR-URL: #277 Fixes: #260 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 4e58211 commit 12912c6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

tools/test.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __init__(self, cases, flaky_tests_mode):
7171
self.total = len(cases)
7272
self.failed = [ ]
7373
self.crashed = 0
74-
self.terminate = False
7574
self.lock = threading.Lock()
75+
self.shutdown_event = threading.Event()
7676

7777
def PrintFailureHeader(self, test):
7878
if test.IsNegative():
@@ -101,17 +101,19 @@ def Run(self, tasks):
101101
for thread in threads:
102102
# Use a timeout so that signals (ctrl-c) will be processed.
103103
thread.join(timeout=10000000)
104+
except (KeyboardInterrupt, SystemExit), e:
105+
self.shutdown_event.set()
104106
except Exception, e:
105107
# If there's an exception we schedule an interruption for any
106108
# remaining threads.
107-
self.terminate = True
109+
self.shutdown_event.set()
108110
# ...and then reraise the exception to bail out
109111
raise
110112
self.Done()
111113
return not self.failed
112114

113115
def RunSingle(self, parallel, thread_id):
114-
while not self.terminate:
116+
while not self.shutdown_event.is_set():
115117
try:
116118
test = self.parallel_queue.get_nowait()
117119
except Empty:
@@ -131,9 +133,8 @@ def RunSingle(self, parallel, thread_id):
131133
output = case.Run()
132134
case.duration = (datetime.now() - start)
133135
except IOError, e:
134-
assert self.terminate
135136
return
136-
if self.terminate:
137+
if self.shutdown_event.is_set():
137138
return
138139
self.lock.acquire()
139140
if output.UnexpectedOutput():

0 commit comments

Comments
 (0)