diff options
author | Matthew Pickering <matthewtpickering@gmail.com> | 2021-05-11 17:39:38 +0100 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2021-05-12 08:25:50 +0100 |
commit | df8ef1a4865ed9d1ec0ac6f1f34465c118060933 (patch) | |
tree | 00e135f76db96c9e14a2997f0e0d9fa9cd42ecfd /testsuite/timeout/timeout.py | |
parent | ad659f711a8e01c6035b9fc3a4074b031211d515 (diff) | |
download | haskell-wip/hpt-oneshot.tar.gz |
testsuite: Teminate processes when the testsuite is interruptedwip/hpt-oneshot
Diffstat (limited to 'testsuite/timeout/timeout.py')
-rw-r--r-- | testsuite/timeout/timeout.py | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/testsuite/timeout/timeout.py b/testsuite/timeout/timeout.py index f3468ad9fb..d6bc0cf326 100644 --- a/testsuite/timeout/timeout.py +++ b/testsuite/timeout/timeout.py @@ -1,33 +1,33 @@ #!/usr/bin/env python -try: +import errno +import os +import signal +import sys +import time - import errno - import os - import signal - import sys - import time +secs = int(sys.argv[1]) +cmd = sys.argv[2] - secs = int(sys.argv[1]) - cmd = sys.argv[2] +def killProcess(pid): + os.killpg(pid, signal.SIGKILL) + for x in range(10): + try: + time.sleep(0.3) + r = os.waitpid(pid, os.WNOHANG) + if r == (0, 0): + os.killpg(pid, signal.SIGKILL) + else: + return + except OSError as e: + if e.errno == errno.ECHILD: + return + else: + raise e - def killProcess(pid): - os.killpg(pid, signal.SIGKILL) - for x in range(10): - try: - time.sleep(0.3) - r = os.waitpid(pid, os.WNOHANG) - if r == (0, 0): - os.killpg(pid, signal.SIGKILL) - else: - return - except OSError as e: - if e.errno == errno.ECHILD: - return - else: - raise e +pid = os.fork() - pid = os.fork() +try: if pid == 0: # child os.setpgrp() @@ -50,7 +50,12 @@ try: sys.exit(99) # unexpected except KeyboardInterrupt: + killProcess(pid) sys.exit(98) +except SystemExit: + raise except: + print("Unexpected error:", sys.exc_info()[0]) + killProcess(pid) raise |