I have this code :
import os
pid = os.fork()
if pid == 0:
os.environ[\'HOME\'] = \"rep1\"
external_function()
else:
os.environ[\'HOME\'] = \"rep2\"
The answer you are looking for is in detail addressed here. There is also an explanation of differences between different OS.
One big issue is that the fork
system call does not exist on Windows. Therefore, when running a Windows OS you cannot use this method. multiprocessing
is a higher-level interface to execute a part of the currently running program. Therefore, it - as forking does - creates a copy of your process current state. That is to say, it takes care of the forking of your program for you.
Therefore, if available you could consider fork()
a lower-level interface to forking a program, and the multiprocessing
library to be a higher-level interface to forking.