I have threads to add items to let's say a global success list.
I know that thread communications should be done via Queue
s, but when reading the Queue documentation, there is no function to get exact count of the queue length.
Queue.qsize() Return the approximate size of the queue. Note, qsize()
0 doesn’t guarantee that a subsequent get() will not block, nor will qsize() < maxsize guarantee that put() will not block.
I have also tried len(queue)
but it doesn't work:
>>> import Queue
>>> q = Queue.Queue()
>>> q.put(1)
>>> q.put(2)
>>> len(q)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: Queue instance has no attribute '__len__'
I have also read about using List
but I don't have definite answer if the data will be corrupted or not.
My only option I can think of right now is to run queue.get()
until queue
is empty to convert to a list. Is there a better choice?