I run the following solution from How can I recover the return value of a function passed to multiprocessing.Process?:
import multiprocessing
from os import getpid
def worker(procnum):
print('I am number %d in process %d' % (procnum, getpid()))
return getpid()
if __name__ == '__main__':
pool = multiprocessing.Pool(processes = 3)
print(pool.map(worker, range(5)))
which is supposed to output something like:
I am number 0 in process 19139
I am number 1 in process 19138
I am number 2 in process 19140
I am number 3 in process 19139
I am number 4 in process 19140
[19139, 19138, 19140, 19139, 19140]
but instead I only get
[4212, 4212, 4212, 4212, 4212]
If I feed pool.map a range of 1,000,000 using more than 10 processes I see at most two different pids.
Why is my copy of multiprocessing
seemingly running everything in the same process?