If you wanted to get the size of the data in the queue as well you could use this instead but it is blocking the queue so it will slow things down. Probably acceptable for debugging. I adapted a recursive version to get the size of the queue and its contents from here: Get size of Python object recursively to handle size of containers within containers · GitHub
def get_size(self, obj, seen=None):
"""Recursively finds size of objects"""
import sys
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
# Important mark as seen *before* entering recursion to gracefully handle
# self-referential objects
seen.add(obj_id)
if isinstance(obj, dict):
size += sum([self.get_size(v, seen) for v in obj.values()])
size += sum([self.get_size(k, seen) for k in obj.keys()])
elif hasattr(obj, '__dict__'):
size += self.get_size(obj.__dict__, seen)
elif hasattr(obj, '__iter__') and not isinstance(obj, (str, bytes, bytearray)):
size += sum([self.get_size(i, seen) for i in obj])
return size
@override(InputReader)
def next(self):
import sys
with self.samples_queue.mutex:
size = self.get_size(self.samples_queue.queue)
print(f"Size of samples queue is: {self.samples_queue.qsize()} taking up {size} bytes", )
return self.samples_queue.get()