From d6db92b7e6e52667c8d32d5c64fef4c9a9895feb Mon Sep 17 00:00:00 2001 From: MinRK Date: Thu, 27 Sep 2012 15:58:00 -0700 Subject: [PATCH] allow iptest to be interrupted Previously `^C` would register as a regular test failure, and the test suite would continue, in which case halting `iptest` meant hitting `^C` nine times. This change makes iptest take notice of sigint in a test runner, and aborts the run. --- IPython/testing/iptest.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/IPython/testing/iptest.py b/IPython/testing/iptest.py index 9e3741610..193228dd5 100644 --- a/IPython/testing/iptest.py +++ b/IPython/testing/iptest.py @@ -396,6 +396,8 @@ class IPTester(object): """Run the stored commands""" try: retcode = self._run_cmd() + except KeyboardInterrupt: + return -signal.SIGINT except: import traceback traceback.print_exc() @@ -412,17 +414,22 @@ class IPTester(object): continue # process is already dead try: - print('Cleaning stale PID: %d' % subp.pid) + print('Cleaning up stale PID: %d' % subp.pid) subp.kill() except: # (OSError, WindowsError) ? # This is just a best effort, if we fail or the process was # really gone, ignore it. pass + else: + for i in range(10): + if subp.poll() is None: + time.sleep(0.1) + else: + break if subp.poll() is None: # The process did not die... - print('... failed. Manual cleanup may be required.' - % subp.pid) + print('... failed. Manual cleanup may be required.') def make_runners(inc_slow=False): """Define the top-level packages that need to be tested. @@ -533,6 +540,9 @@ def run_iptestall(inc_slow=False): res = runner.run() if res: failed.append( (name, runner) ) + if res == -signal.SIGINT: + print("Interrupted") + break finally: os.chdir(curdir) t_end = time.time()