forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp_preload.py
More file actions
33 lines (30 loc) · 854 Bytes
/
mp_preload.py
File metadata and controls
33 lines (30 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import multiprocessing
multiprocessing.Lock()
#
# This test verifies that preload is behaving as expected. By preloading
# both __main__ and mp_preload_import, both this module and mp_preload_import
# should be loaded in the forkserver process when it serves new processes.
# This means that each new process and call to f() will not cause additional
# module loading.
#
# The expected output is then:
# mp_preload
# mp_preload
# mp_preload_import
# f
# f
# f
#
# Any deviation from this means something is broken.
#
def f():
import test.mp_preload_import
print('f')
print("mp_preload")
if __name__ == "__main__":
ctx = multiprocessing.get_context("forkserver")
ctx.set_forkserver_preload(["__main__","test.mp_preload_import"], True)
for i in range(3):
proc = ctx.Process(target=f)
proc.start()
proc.join()