Skip to content

Commit dcfabfd

Browse files
committed
join all threads by the end
1 parent fa4e32e commit dcfabfd

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

graalpython/com.oracle.graal.python.test/src/graalpytest.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
import threading
5656
import _thread
5757
result_lock = threading.RLock()
58+
threads = []
5859
if os.environ.get(b"ENABLE_THREADED_GRAALPYTEST") == b"true":
59-
thread_count = max(os.cpu_count(), 16)
60-
thread_token = threading.Semaphore(thread_count)
60+
thread_count = min(os.cpu_count(), 16)
6161
print("Running with %d threads" % thread_count)
6262
else:
63-
thread_count = 0
64-
thread_token = None
63+
thread_count = 1
64+
thread_token = threading.Semaphore(thread_count)
6565

6666

6767
def dump_truffle_ast(func):
@@ -120,14 +120,12 @@ def do_run():
120120
r = self.run_safely(func)
121121
with result_lock:
122122
self.success() if r else self.failure()
123-
if thread_token:
124-
thread_token.release()
123+
thread_token.release()
125124

126-
if thread_token:
127-
thread_token.acquire()
128-
threading.Thread(target=do_run).start()
129-
else:
130-
do_run()
125+
thread_token.acquire()
126+
new_thread = threading.Thread(target=do_run)
127+
threads.append(new_thread)
128+
new_thread.start()
131129

132130
def success(self):
133131
self.passed += 1
@@ -340,11 +338,9 @@ def run(self):
340338
self.failed += testcase.failed
341339
if verbose:
342340
print()
343-
for i in range(thread_count):
344-
print("waiting for %d tests to finish" % (thread_count - i))
345-
thread_token.acquire() # waits until all threads are exited
346-
for i in range(thread_count):
347-
thread_token.release()
341+
for i, t in enumerate(threads):
342+
print("waiting for %d tests to finish" % (len(threads) - i))
343+
t.join(timeout=0)
348344
print("\n\nRan %d tests (%d passes, %d failures)" % (self.passed + self.failed, self.passed, self.failed))
349345
for e in self.exceptions:
350346
print(e)

0 commit comments

Comments
 (0)