I am trying to use Python multiprocessing
module. Here is some example code
from multiprocessing import Process
def foo():
print("Hello" )
def foo2():
print("Hello again" )
if __name__ == '__main__':
print('program started')
global p1, p2
p1 = Process(target=foo)
p2 = Process(target=foo2)
print(p1.is_alive())
p1.start()
p2.start()
p1.join()
p2.join()
As you can see, foo
and foo2
are simple functions. I added the __name__
guard after people suggested it: Python multiprocessing processes instantly die after being started.
When I run this on my computer, I get the following output:
program started
False
The code seems to be working, so can somebody please explain?
I am using MacOS.