A FIFO (First in first out) queue has two main methods:
put()
, with puts an element to the queue,get()
, which returns next element.
If queue is empty, get()
blocks.
Create a queue in which every element that was added more than timeout
seconds ago got removed from the queue.
q = TimeoutQueue(timeout=5)
q.put(1)
q.put(2)
print(q.get())
# 1
time.sleep(6)
q.put(3)
print(q.get())
# 3