I have written the following code in Python 3 using the multiprocessing module. It's more of a test script to see how to use Event
. However, it's not working.
import multiprocessing, time
from multiprocessing import Process, Event
event = Event()
def f(n):
if n == 1:
print("starting")
event.wait()
print("Done!")
if n == 2:
time.sleep(3)
event.set()
print("setting")
if __name__ == "__main__":
p1 = Process(target = f, args = (1,))
p2 = Process(target = f, args = (2,))
p1.start()
p2.start()
time.sleep(1000)
However, when I run this I only get the output:
starting
setting
I want to get the output:
starting
setting
Done!
But for some reason the p1
Process is not moving on with its code after event.set() has been called by the p2
process.
Any ideas why this is happening?