On this page
queue.LifoQueue
Prev: queue.Full | Up: queue | Next: queue.PriorityQueue
Rel: queue.Empty, queue.Full, queue.PriorityQueue, queue.Queue
Ref: docs.python.org — queue.LifoQueue
Tags: #public #python3 #stdlib #queue
Import
import queue
from queue import LifoQueue
Signature & Overview
queue.LifoQueue(maxsize=0)
Variant of Queue that retrieves most recently added entries first.
Methods & Attributes
LifoQueue.empty(self)— Return True if the queue is empty, False otherwise (not reliable!).LifoQueue.full(self)— Return True if the queue is full, False otherwise (not reliable!).LifoQueue.get(self, block=True, timeout=None)— Remove and return an item from the queue.LifoQueue.get_nowait(self)— Remove and return an item from the queue without blocking.LifoQueue.join(self)— Blocks until all items in the Queue have been gotten and processed.LifoQueue.put(self, item, block=True, timeout=None)— Put an item into the queue.LifoQueue.put_nowait(self, item)— Put an item into the queue without blocking.LifoQueue.qsize(self)— Return the approximate size of the queue (not reliable!).LifoQueue.shutdown(self, immediate=False)— Shut-down the queue, making queue gets and puts raise ShutDown.LifoQueue.task_done(self)— Indicate that a formerly enqueued task is complete.
Usage
import queue
stack: queue.LifoQueue[str] = queue.LifoQueue()
stack.put("first")
stack.put("second")
assert stack.get() == "second" and stack.get() == "first"
Gotchas
- Thread-safe LIFO stack: For single-threaded stacks, a plain
list(.append()/.pop()) is much faster.
REPL Inspect
from queue import LifoQueue
help(LifoQueue)
Linked from
Related notes
- tuts/python3/stdlib_module/queue/Empty Linked here; links to this page; shared tags: #queue, #stdlib
- tuts/python3/stdlib_module/queue/Full Linked here; links to this page; shared tags: #queue, #stdlib
- tuts/python3/stdlib_module/queue/PriorityQueue Linked here; links to this page; shared tags: #queue, #stdlib
- tuts/python3/stdlib_module/queue/Queue Linked here; links to this page; shared tags: #queue, #stdlib
- tuts/python3/stdlib_module/queue/ShutDown links to this page; shared tags: #queue, #stdlib
- tuts/python3/stdlib_module/queue/SimpleQueue links to this page; shared tags: #queue, #stdlib
- tuts/python3/stdlib_module/queue links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib