summaryrefslogtreecommitdiff
path: root/testsuite/driver/testlib.py
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-05-11 17:39:38 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2021-05-12 08:25:50 +0100
commitdf8ef1a4865ed9d1ec0ac6f1f34465c118060933 (patch)
tree00e135f76db96c9e14a2997f0e0d9fa9cd42ecfd /testsuite/driver/testlib.py
parentad659f711a8e01c6035b9fc3a4074b031211d515 (diff)
downloadhaskell-wip/hpt-oneshot.tar.gz
testsuite: Teminate processes when the testsuite is interruptedwip/hpt-oneshot
Diffstat (limited to 'testsuite/driver/testlib.py')
-rw-r--r--testsuite/driver/testlib.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index db40d6f82f..50f5133386 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -37,6 +37,11 @@ if config.use_threads:
import threading
pool_sema = threading.BoundedSemaphore(value=config.threads)
+def acquire_all() -> None:
+ global pool_sema
+ for i in range(config.threads):
+ pool_sema.acquire()
+
global wantToStop
wantToStop = False
@@ -2340,6 +2345,19 @@ def dump_file(f: Path):
except Exception:
print('')
+# Wait for a process but kill it if a global trigger is sent
+def process_loop(r):
+ finished = False
+ while not (stopping() or finished):
+ try:
+ r.wait(timeout=1)
+ finished = True
+ except subprocess.TimeoutExpired:
+ pass
+ if not finished:
+ r.terminate()
+ return r.communicate()
+
def runCmd(cmd: str,
stdin: Union[None, Path]=None,
stdout: Union[None, Path]=None,
@@ -2372,8 +2390,8 @@ def runCmd(cmd: str,
stdout=subprocess.PIPE,
stderr=hStdErr,
env=ghc_env)
+ stdout_buffer, stderr_buffer = process_loop(r)
- stdout_buffer, stderr_buffer = r.communicate()
finally:
if stdin_file:
stdin_file.close()