Out of curiosity and trying to understand the subprocess module: Is it possible to do something like:
import subprocess
def myfun(arg):
# do stuff
arg = something;
p = subprocess.Popen(["myfun","arg"])
without putting “myfun” in a file of its own? It seems like this would in general be a scary thing to do if you are not careful about cleaning up child processes.
You can pass
Popenapreexec_fn, which is a callable object executed in the child process before the command is exec’d. A more standard approach is to use themultiprocessingmodule, which requires a Python function instead of an external command.