8000 MAINT: use a try/finally to make the deadlock protection more robust · numpy/numpy@c20ac88 · GitHub
[go: up one dir, main page]

Skip to content

Commit c20ac88

Browse files
ngoldbaumcharris
authored andcommitted
MAINT: use a try/finally to make the deadlock protection more robust
1 parent d494647 commit c20ac88

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

numpy/testing/_private/utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,18 +2699,19 @@ def run_threaded(func, max_workers=8, pass_count=False,
26992699
if pass_barrier:
27002700
barrier = threading.Barrier(max_workers)
27012701
args.append(barrier)
2702+
if pass_count:
2703+
all_args = [(func, i, *args) for i in range(max_workers)]
2704+
else:
2705+
all_args = [(func, *args) for i in range(max_workers)]
27022706
try:
2703-
if pass_count:
2704-
futures = [tpe.submit(func, i, *args) for i in
2705-
range(max_workers)]
2706-
else:
2707-
futures = [tpe.submit(func, *args) for _ in
2708-
range(max_workers)]
2709-
except RuntimeError:
2710-
# python raises RuntimeError when it can't spawn new threads
2711-
if pass_barrier:
2707+
n_submitted = 0
2708+
futures = []
2709+
for arg in all_args:
2710+
futures.append(tpe.submit(*arg))
2711+
n_submitted += 1
2712+
finally:
2713+
if n_submitted < max_workers and pass_barrier:
27122714
barrier.abort()
2713-
raise
27142715
for f in futures:
27152716
f.result()
27162717

0 commit comments

Comments
 (0)
0