Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get length of Queue in Python's multiprocessing library

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?

Python's inbuilt len() function does not work.

like image 827
lachy Avatar asked Jan 31 '17 07:01

lachy


1 Answers

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.

like image 172
Shane Avatar answered Oct 20 '22 04:10

Shane