From 23c575d917b2f35d3d04df604b8985580b2d2c7f Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Sat, 4 Jan 2025 12:59:51 +0100 Subject: [PATCH] make sure all threads start iterating at the same moment in the test --- Lib/test/test_free_threading/test_enumerate.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_free_threading/test_enumerate.py b/Lib/test/test_free_threading/test_enumerate.py index bcc6588d34fca5..7e5ba63e59684a 100644 --- a/Lib/test/test_free_threading/test_enumerate.py +++ b/Lib/test/test_free_threading/test_enumerate.py @@ -14,22 +14,25 @@ def test_threading(self): number_of_iterations = 8 n = 100 start = sys.maxsize - 40 - - def work(enum, start): + workers_enabled = False + def work(enum): while True: - try: - _ = next(enum) - except StopIteration: - break + if workers_enabled: + print('go!') + try: + _ = next(enum) + except StopIteration: + break for _ in range(number_of_iterations): enum = enumerate(range(start, start + n)) worker_threads = [] for ii in range(number_of_threads): worker_threads.append( - Thread(target=work, args=[enum, start])) + Thread(target=work, args=[enum])) for t in worker_threads: t.start() + workers_enabled = True # make sure to start all threads simultaneously for t in worker_threads: t.join()