Does anyone know a pythonic way of iterating over the elements of a Queue.Queue without removing them from the Queue. I have a producer/consumer-type p
Queue.Queue
You can subclass queue.Queue to achieve this in a thread-safe way:
queue.Queue
import queue class ImprovedQueue(queue.Queue): def to_list(self): """ Returns a copy of all items in the queue without removing them. """ with self.mutex: return list(self.queue)