Why does Queue.Queue
have a task_done
method while multiprocessing.Queue
has no such method?
Queue. task_done () Indicate that a formerly enqueued task is complete. Used by queue consumer threads. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
A queue is a data structure on which items can be added by a call to put() and from which items can be retrieved by a call to get(). The multiprocessing. Queue provides a first-in, first-out FIFO queue, which means that the items are retrieved from the queue in the order they were added.
Queues are thread and process safe.
Multiprocessing outshines threading in cases where the program is CPU intensive and doesn't have to do any IO or user interaction. For example, any program that just crunches numbers will see a massive speedup from multiprocessing; in fact, threading will probably slow it down.
I think you need JoinableQueue.
My guess would be: multithreading
module was implemented very early, multiprocessing
module came in 2.6 version.
The queue design was slightly corrected for multiprocessing
and offers better flexibility than the multithreading
, because you can choose between Queue
, SimpleQueue
and JoinableQueue
depending on your use cases (speed vs reliability).
Now modifing multithreading
like this would have caused backwards incompatibility, since join
and task_done
methods would have to be removed. Imagine the code needed to be refactored, new tests had to be written, API broken - for me clearly no benefits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With