开发者

What is the easiest way to know how many bytes of data is stored at a certain moment in a Python Queue?

开发者 https://www.devze.com 2023-03-25 07:04 出处:网络
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'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 bytes

What is the easiest way to know how many bytes of data is stored at a certain moment in a queue?

cheers,

Jay

0

精彩评论

暂无评论...
验证码 换一张
取 消