MCPcopy Create free account
hub / github.com/python/cpython / test_reversed

Method test_reversed

Lib/test/test_free_threading/test_reversed.py:10–36  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

8
9 @threading_helper.reap_threads
10 def test_reversed(self):
11 # Iterating over the iterator with multiple threads should not
12 # emit TSAN warnings
13 number_of_iterations = 10
14 number_of_threads = 10
15 size = 1_000
16
17 barrier = Barrier(number_of_threads)
18 def work(r):
19 barrier.wait()
20 while True:
21 try:
22 l = r.__length_hint__()
23 next(r)
24 except StopIteration:
25 break
26 assert 0 <= l <= size
27 x = tuple(range(size))
28
29 for _ in range(number_of_iterations):
30 r = reversed(x)
31 worker_threads = []
32 for _ in range(number_of_threads):
33 worker_threads.append(Thread(target=work, args=[r]))
34 with threading_helper.start_threads(worker_threads):
35 pass
36 barrier.reset()
37
38if __name__ == "__main__":
39 unittest.main()

Callers

nothing calls this directly

Calls 4

resetMethod · 0.95
BarrierClass · 0.90
ThreadClass · 0.90
appendMethod · 0.45

Tested by

no test coverage detected