Debian Codegraph @

Lib/test/test_free_threading/test_collections.py

raw
1 import unittest
2 from collections import deque
3 from copy import copy
4 from test.support import threading_helper
5
6 threading_helper.requires_working_threading(module=True)
7
8
9 class TestDeque(unittest.TestCase):
10 def test_copy_race(self):
11 # gh-144809: Test that deque copy is thread safe. It previously
12 # could raise a "deque mutated during iteration" error.
13 d = deque(range(100))
14
15 def mutate():
16 for i in range(1000):
17 d.append(i)
18 if len(d) > 200:
19 d.popleft()
20
21 def copy_loop():
22 for _ in range(1000):
23 copy(d)
24
25 threading_helper.run_concurrently([mutate, copy_loop])
26
27
28 if __name__ == "__main__":
29 unittest.main()