This is my code:
import multiprocessing
import time
import os
def worker():
print str(os.getpid()) + " is going to sleep..."
time.sleep(1)
print str(os.getpid()) + " woke up!"
return
if __name__ == "__main__":
pool = multiprocessing.Pool(processes = 8)
for _ in range(5):
pool.apply_async(worker())
And my output:
23173 is going to sleep...
23173 woke up!
23173 is going to sleep...
23173 woke up!
23173 is going to sleep...
23173 woke up!
23173 is going to sleep...
23173 woke up!
23173 is going to sleep...
23173 woke up!
This output appears sequentially and obviously all the outputs have the same id. What I'm expecting to see is 5 separate processes alerting they that are going to sleep and then waking up at similar times.
Why is this not happening? I have done a lot of research on stackoverflow and other sites and it seems like everyone is assured that this should have the "worker" callable applied across multiple processes, but it appears not to be.
apply_asynch(worker)without the().