I'm using the Python Queue implementation (http://docs.python.org/library/queue.html) and I was wondering how to get the actual size in bytes of the queue?
I know one can retrieve the number of elements in it, but that doesn't help me as the elements could be of variable size.
Also sys.getsizeof() doesn't help me.
#!/usr/bin/python
import Queue,sys
q1 = Queue.Queue(0)
q2 = Queue.Queue(0)
for number in range (0,1000):
q1.put(number)
for number in range (0,10000):
q2.put(number)
print "%s elements, %s bytes"%(q1.qsize(),sys.getsizeof(q1))
print "%s elements, %s bytes"%(q2.qsize(),sys.getsizeof(q2))
1000 elements, 72 bytes
10000 elements开发者_开发百科, 72 bytesWhat is the easiest way to know how many bytes of data is stored at a certain moment in a queue?
cheers,
Jay
精彩评论