Yes we can check the length of queue object created from collections.
from collections import deque
class Queue():
def __init__(self,batchSize=32):
#self.batchSie = batchSize
self._queue = deque(maxlen=batchSize)
def enqueue(self, items):
''' Appending the items to the queue'''
self._queue.append(items)
def dequeue(self):
'''remoe the items from the top if the queue becomes full '''
return self._queue.popleft()
Creating an object of class
q = Queue(batchSize=64)
q.enqueue([1,2])
q.enqueue([2,3])
q.enqueue([1,4])
q.enqueue([1,22])
Now retrieving the length of the queue
#check the len of queue
print(len(q._queue))
#you can print the content of the queue
print(q._queue)
#Can check the content of the queue
print(q.dequeue())
#Check the length of retrieved item
print(len(q.dequeue()))
check the results in attached screen shot
Hope this helps...
len(queue)
? That's usually how Python handles element counts. – Povertyprint(len(my_queue.queue))
worked for me. – OdoQueue
are going to end up here, and the accepted answer simply will not work for aQueue
. (and yes, I know adeque
is also a type of queue - it's just an unfortunate word in this case...) – Delmadelmarqueue.Queue
(ormultiprocessing.Queue
) object, refer to Get length of Queue in Python's multiprocessing library - Stack Overflow – Honourable