I want to save the task result in to a queue, the tasks is run in multiple process. After all tasks running done, read result from the queue.
Why the queue size printed in child task is right, but in parent process is 0? Also I can not get the queue data in parent. How to resolve this?
Code in Python3:
import multiprocessing
que = multiprocessing.Queue()
def task(n):
que.put(n)
print("Child: queue len is %d" % que.qsize())
if __name__ == '__main__':
pool = multiprocessing.Pool()
pool.map(task, range(10))
print("Parent: queue len is %d" % que.qsize())
Output:
Child: queue len is 1
Child: queue len is 2
Child: queue len is 3
Child: queue len is 4
Child: queue len is 5
Child: queue len is 6
Child: queue len is 7
Child: queue len is 8
Child: queue len is 9
Child: queue len is 10
Parent: queue len is 0 // Why here is not 10??