MCPcopy Index your code
hub / github.com/python/cpython / test_module_load_race

Method test_module_load_race

Lib/test/test_importlib/test_lazy.py:151–179  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

149
150 @threading_helper.requires_working_threading()
151 def test_module_load_race(self):
152 with test_util.uncache(TestingImporter.module_name):
153 loader = TestingImporter()
154 module = self.new_module(loader=loader)
155 self.assertEqual(loader.load_count, 0)
156
157 class RaisingThread(threading.Thread):
158 exc = None
159 def run(self):
160 try:
161 super().run()
162 except Exception as exc:
163 self.exc = exc
164
165 def access_module():
166 return module.attr
167
168 threads = []
169 for _ in range(2):
170 threads.append(thread := RaisingThread(target=access_module))
171 thread.start()
172
173 # Races could cause errors
174 for thread in threads:
175 thread.join()
176 self.assertIsNone(thread.exc)
177
178 # Or multiple load attempts
179 self.assertEqual(loader.load_count, 1)
180
181 def test_lazy_self_referential_modules(self):
182 # Directory modules with submodules that reference the parent can attempt to access

Callers

nothing calls this directly

Calls 8

new_moduleMethod · 0.95
TestingImporterClass · 0.85
RaisingThreadClass · 0.85
assertIsNoneMethod · 0.80
assertEqualMethod · 0.45
appendMethod · 0.45
startMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected