Skip to content

Commit cc3c42b

Browse files
committed
enable tests
1 parent 070c877 commit cc3c42b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import unittest
2+
import sys
3+
from threading import Thread, Barrier
4+
from itertools import batched
5+
from test.support import threading_helper
6+
7+
8+
class EnumerateThreading(unittest.TestCase):
9+
10+
@threading_helper.reap_threads
11+
@threading_helper.requires_working_threading()
12+
def test_threading(self):
13+
number_of_threads = 10
14+
number_of_iterations = 20
15+
barrier = Barrier(number_of_threads)
16+
def work(it):
17+
barrier.wait()
18+
while True:
19+
try:
20+
_ = next(it)
21+
except StopIteration:
22+
break
23+
24+
data = tuple(range(1000))
25+
for it in range(number_of_iterations):
26+
batch_iterator = batched(data, 2)
27+
worker_threads = []
28+
for ii in range(number_of_threads):
29+
worker_threads.append(
30+
Thread(target=work, args=[batch_iterator]))
31+
for t in worker_threads:
32+
t.start()
33+
for t in worker_threads:
34+
t.join()
35+
36+
barrier.reset()
37+
38+
if __name__ == "__main__":
39+
unittest.main()

0 commit comments

Comments
 (0)