Skip to content

Commit

Permalink
tools: enable ctrl-c for parallel tests
Browse files Browse the repository at this point in the history
use a threading.Event instead of a boolean attribute.

PR-URL: #277
Fixes: #260
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
chrisdickinson committed Jan 9, 2015
1 parent 4e58211 commit 12912c6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def __init__(self, cases, flaky_tests_mode):
self.total = len(cases)
self.failed = [ ]
self.crashed = 0
self.terminate = False
self.lock = threading.Lock()
self.shutdown_event = threading.Event()

def PrintFailureHeader(self, test):
if test.IsNegative():
Expand Down Expand Up @@ -101,17 +101,19 @@ def Run(self, tasks):
for thread in threads:
# Use a timeout so that signals (ctrl-c) will be processed.
thread.join(timeout=10000000)
except (KeyboardInterrupt, SystemExit), e:
self.shutdown_event.set()
except Exception, e:
# If there's an exception we schedule an interruption for any
# remaining threads.
self.terminate = True
self.shutdown_event.set()
# ...and then reraise the exception to bail out
raise
self.Done()
return not self.failed

def RunSingle(self, parallel, thread_id):
while not self.terminate:
while not self.shutdown_event.is_set():
try:
test = self.parallel_queue.get_nowait()
except Empty:
Expand All @@ -131,9 +133,8 @@ def RunSingle(self, parallel, thread_id):
output = case.Run()
case.duration = (datetime.now() - start)
except IOError, e:
assert self.terminate
return
if self.terminate:
if self.shutdown_event.is_set():
return
self.lock.acquire()
if output.UnexpectedOutput():
Expand Down

0 comments on commit 12912c6

Please sign in to comment.