Skip to content

Commit

Permalink
make sure all threads start iterating at the same moment in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Jan 4, 2025
1 parent 167d606 commit 23c575d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Lib/test/test_free_threading/test_enumerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 23c575d

Please sign in to comment.