|
55 | 55 | import threading
|
56 | 56 | import _thread
|
57 | 57 | result_lock = threading.RLock()
|
| 58 | +threads = [] |
58 | 59 | 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) |
61 | 61 | print("Running with %d threads" % thread_count)
|
62 | 62 | else:
|
63 |
| - thread_count = 0 |
64 |
| - thread_token = None |
| 63 | + thread_count = 1 |
| 64 | +thread_token = threading.Semaphore(thread_count) |
65 | 65 |
|
66 | 66 |
|
67 | 67 | def dump_truffle_ast(func):
|
@@ -120,14 +120,12 @@ def do_run():
|
120 | 120 | r = self.run_safely(func)
|
121 | 121 | with result_lock:
|
122 | 122 | self.success() if r else self.failure()
|
123 |
| - if thread_token: |
124 |
| - thread_token.release() |
| 123 | + thread_token.release() |
125 | 124 |
|
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() |
131 | 129 |
|
132 | 130 | def success(self):
|
133 | 131 | self.passed += 1
|
@@ -340,11 +338,9 @@ def run(self):
|
340 | 338 | self.failed += testcase.failed
|
341 | 339 | if verbose:
|
342 | 340 | 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) |
348 | 344 | print("\n\nRan %d tests (%d passes, %d failures)" % (self.passed + self.failed, self.passed, self.failed))
|
349 | 345 | for e in self.exceptions:
|
350 | 346 | print(e)
|
|
0 commit comments