Skip to content

Commit 30dd92f

Browse files
committed
Merge remote-tracking branch 'origin/develop' into bb/atof-v01
2 parents 1ab86ce + 3e9b632 commit 30dd92f

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

ci/scripts/run_tests.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import signal
2222
import subprocess
2323
import sys
24-
from concurrent.futures import ProcessPoolExecutor
25-
from concurrent.futures import as_completed
24+
from multiprocessing.pool import Pool
2625
from pathlib import Path
2726

2827
from dotenv import dotenv_values
@@ -245,42 +244,58 @@ def main(junit_xml: str | None,
245244

246245
failures = 0
247246

248-
with ProcessPoolExecutor(max_workers=jobs) as executor:
249-
ex = executor
247+
orig_handler = signal.getsignal(signal.SIGINT)
250248

251-
def shutdown_executor(_signum, _frame, wait: bool = False):
249+
def _restore_handler():
250+
if orig_handler is not None:
251+
signal.signal(signal.SIGINT, orig_handler)
252+
253+
with Pool(processes=jobs) as pool:
254+
ex = pool
255+
256+
def shutdown_pool(_signum, _frame):
252257
nonlocal ex
258+
259+
shutdown_msg = "Exiting"
253260
if ex is not None:
254-
print("Shutting down executor...")
255-
ex.shutdown(wait=wait, cancel_futures=True)
261+
print("Shutting down pool...")
262+
ex.terminate()
263+
ex.join()
264+
if _signum is not None:
265+
shutdown_msg = f"Received signal {_signum}, exiting"
266+
256267
else:
257-
print("Executor not found")
268+
print("Pool not found")
269+
270+
_restore_handler()
271+
raise SystemExit(shutdown_msg)
258272

259-
signal.signal(signal.SIGINT, shutdown_executor)
273+
signal.signal(signal.SIGINT, shutdown_pool)
260274
futs = [
261-
ex.submit(run_one,
262-
p,
263-
enable_coverage=cov_xml is not None,
264-
enable_junit=junit_xml is not None,
265-
run_slow=run_slow,
266-
run_integration=run_integration,
267-
exitfirst=exitfirst,
268-
is_verbose=has_verbose_flag,
269-
extra_flags=extra_flags,
270-
no_tests=no_tests) for p in projects
275+
pool.apply_async(run_one,
276+
args=(p, ),
277+
kwds=dict(enable_coverage=cov_xml is not None,
278+
enable_junit=junit_xml is not None,
279+
run_slow=run_slow,
280+
run_integration=run_integration,
281+
exitfirst=exitfirst,
282+
is_verbose=has_verbose_flag,
283+
extra_flags=extra_flags,
284+
no_tests=no_tests)) for p in projects
271285
]
272286
try:
273-
for fut in as_completed(futs):
274-
if fut.result() != 0:
287+
for fut in futs:
288+
if fut.get() != 0:
275289
failures += 1
276290
if exitfirst:
277291
raise TestFailure("Exiting on first failure as requested.")
278292

279293
except TestFailure:
280294
print("Cancelling remaining tests...")
281-
shutdown_executor(None, None, wait=True)
295+
shutdown_pool(None, None)
282296
finally:
283297
ex = None
298+
_restore_handler()
284299
for p in projects:
285300
sh(["rm", "-rf", str(p / ".venv")])
286301

0 commit comments

Comments
 (0)