tools: enable ctrl-c for parallel tests
use a threading.Event instead of a boolean attribute. PR-URL: https://github.com/iojs/io.js/pull/277 Fixes: https://github.com/iojs/io.js/issues/260 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
4e58211bb7
commit
12912c6b30
@ -71,8 +71,8 @@ class ProgressIndicator(object):
|
|||||||
self.total = len(cases)
|
self.total = len(cases)
|
||||||
self.failed = [ ]
|
self.failed = [ ]
|
||||||
self.crashed = 0
|
self.crashed = 0
|
||||||
self.terminate = False
|
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
|
self.shutdown_event = threading.Event()
|
||||||
|
|
||||||
def PrintFailureHeader(self, test):
|
def PrintFailureHeader(self, test):
|
||||||
if test.IsNegative():
|
if test.IsNegative():
|
||||||
@ -101,17 +101,19 @@ class ProgressIndicator(object):
|
|||||||
for thread in threads:
|
for thread in threads:
|
||||||
# Use a timeout so that signals (ctrl-c) will be processed.
|
# Use a timeout so that signals (ctrl-c) will be processed.
|
||||||
thread.join(timeout=10000000)
|
thread.join(timeout=10000000)
|
||||||
|
except (KeyboardInterrupt, SystemExit), e:
|
||||||
|
self.shutdown_event.set()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
# If there's an exception we schedule an interruption for any
|
# If there's an exception we schedule an interruption for any
|
||||||
# remaining threads.
|
# remaining threads.
|
||||||
self.terminate = True
|
self.shutdown_event.set()
|
||||||
# ...and then reraise the exception to bail out
|
# ...and then reraise the exception to bail out
|
||||||
raise
|
raise
|
||||||
self.Done()
|
self.Done()
|
||||||
return not self.failed
|
return not self.failed
|
||||||
|
|
||||||
def RunSingle(self, parallel, thread_id):
|
def RunSingle(self, parallel, thread_id):
|
||||||
while not self.terminate:
|
while not self.shutdown_event.is_set():
|
||||||
try:
|
try:
|
||||||
test = self.parallel_queue.get_nowait()
|
test = self.parallel_queue.get_nowait()
|
||||||
except Empty:
|
except Empty:
|
||||||
@ -131,9 +133,8 @@ class ProgressIndicator(object):
|
|||||||
output = case.Run()
|
output = case.Run()
|
||||||
case.duration = (datetime.now() - start)
|
case.duration = (datetime.now() - start)
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
assert self.terminate
|
|
||||||
return
|
return
|
||||||
if self.terminate:
|
if self.shutdown_event.is_set():
|
||||||
return
|
return
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
if output.UnexpectedOutput():
|
if output.UnexpectedOutput():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user