1) Does the multiprocessing
module support Python script files I can use to start a second process instead of a function?
Currently I use multiprocessing.Process
which takes a function but I would like to execute foo.py
instead. I could use subprocess.Popen
but the benefit of multiprocessing.Process
is that I can pass objects (even if they are just pickled).
When I use multiprocessing.Process, why is my_module imported in the child process but print("foo") is not executed?
2) When I use multiprocessing.Process
, why is my_module
imported in the child process but print("foo")
is not executed? How is my_module available although the main scope is not executed?
import multiprocessing
import my_module
print("foo")
def worker():
print("bar")
my_module.foo()
return
p = multiprocessing.Process(target=worker, args=(1,2, d))
p.start()
p.join()