My requirement is similar to Multiple producers, single consumer
except i need it in python
I have created an application that spawns 5 concurrent processes (I am using multiprocessing library).These 5 process are independently producing output in dict format.
Earlier I was printing the output to console, but now would like to output it to a file.
I am looking for a pattern where all my 5 producers write to a shared queue that supports concurrent writes.
And a single consumer process that too has access to this queue and consumes the data from it, with the ability to wait if there is no data to write and terminate when producers are done with their task.
Thanks Anuj
since you are already using multiprocess, all you need is the Queue class
and a sample (modified from the Queue docs)
Edit:
For multiple answers from each child replace the last for loop with: