Test concurrent accesses to lazily initialized code attributes
(self)
| 40 | @threading_helper.requires_working_threading() |
| 41 | class TestCode(TestCase): |
| 42 | def test_code_attrs(self): |
| 43 | """Test concurrent accesses to lazily initialized code attributes""" |
| 44 | code_objects = [] |
| 45 | for _ in range(1000): |
| 46 | code_objects.append(compile("a + b", "<string>", "eval")) |
| 47 | |
| 48 | def run_in_thread(): |
| 49 | for code in code_objects: |
| 50 | self.assertIsInstance(code.co_code, bytes) |
| 51 | self.assertIsInstance(code.co_freevars, tuple) |
| 52 | self.assertIsInstance(code.co_varnames, tuple) |
| 53 | |
| 54 | threads = [Thread(target=run_in_thread) for _ in range(2)] |
| 55 | for thread in threads: |
| 56 | thread.start() |
| 57 | for thread in threads: |
| 58 | thread.join() |
| 59 | |
| 60 | @unittest.skipUnless(ctypes, "ctypes is required") |
| 61 | def test_request_code_extra_index_concurrent(self): |