MCPcopy Index your code
hub / github.com/RustPython/RustPython / fork_with_import_lock

Method fork_with_import_lock

Lib/test/test_fork1.py:69–90  ·  view source on GitHub ↗
(level)

Source from the content-addressed store, hash-verified

67 exitcode = 42
68 # Issue 9573: this used to trigger RuntimeError in the child process
69 def fork_with_import_lock(level):
70 release = 0
71 in_child = False
72 try:
73 try:
74 for i in range(level):
75 imp.acquire_lock()
76 release += 1
77 pid = os.fork()
78 in_child = not pid
79 finally:
80 for i in range(release):
81 imp.release_lock()
82 except RuntimeError:
83 if in_child:
84 if support.verbose > 1:
85 print("RuntimeError in child")
86 os._exit(1)
87 raise
88 if in_child:
89 os._exit(exitcode)
90 self.wait_impl(pid, exitcode=exitcode)
91
92 # Check this works with various levels of nested
93 # import in the main thread

Callers

nothing calls this directly

Calls 5

release_lockMethod · 0.80
printFunction · 0.50
acquire_lockMethod · 0.45
_exitMethod · 0.45
wait_implMethod · 0.45

Tested by

no test coverage detected