问题
I have a multiprocessing.Manager
object that contains a multiprocessing.Queue
to manage all of the work that I want a group of processes to do. I would like to get the number of elements left in this queue and was wondering how to do this?
The len
function does not work.
回答1:
If the queue you are talking about is multiprocessing.Queue
, try to use qsize() method for multiprocessing.Queue
objects, but be careful:
qsize()
Return the approximate size of the queue. Because of multithreading/multiprocessing semantics, this number is not reliable.
Note that this may raise NotImplementedError on Unix platforms like Mac OS X where sem_getvalue() is not implemented.
来源:https://stackoverflow.com/questions/41952413/get-length-of-queue-in-pythons-multiprocessing-library