Get length of Queue in Python's multiprocessing library

吃可爱长大的小学妹 提交于 2019-12-11 04:06:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!