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

Function task

Lib/test/test_importlib/test_threaded_import.py:24–42  ·  view source on GitHub ↗
(N, done, done_tasks, errors)

Source from the content-addressed store, hash-verified

22threading_helper.requires_working_threading(module=True)
23
24def task(N, done, done_tasks, errors):
25 try:
26 # We don't use modulefinder but still import it in order to stress
27 # importing of different modules from several threads.
28 if len(done_tasks) % 2:
29 import modulefinder
30 import random
31 else:
32 import random
33 import modulefinder
34 # This will fail if random is not completely initialized
35 x = random.randrange(1, 3)
36 except Exception as e:
37 errors.append(e.with_traceback(None))
38 finally:
39 done_tasks.append(threading.get_ident())
40 finished = len(done_tasks) == N
41 if finished:
42 done.set()
43
44# Create a circular import structure: A -> C -> B -> D -> A
45# NOTE: `time` is already loaded and therefore doesn't threaten to deadlock.

Calls 3

randrangeMethod · 0.80
appendMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…