liveBook · Manning

Deque

As explained in Python Concurrency with asyncio

A deque is a double-ended queue that supports insertion and removal at both ends.

A deque, or double-ended queue, supports insertion and removal at both ends. A bounded deque is useful when an application must retain only its newest items. section 8.4.1

A deque solves practical buffering problems by:

  • Keeping messages in display order while discarding older items automatically when its maximum size is reached. section 8.4.1
  • Buffering user input one character at a time and removing the most recent character when Backspace is pressed. section 8.4.1
  • Triggering a redraw after each appended message so the visible output stays synchronized with the buffer. section 8.4.1

A bounded message store

A MessageStore can wrap deque(maxlen=max_size). Each append adds a message and invokes a redraw callback. Once the deque is full, adding another message removes the oldest item, producing terminal scrolling without retaining the entire output history. section 8.4.1

How Python Concurrency with asyncio covers it

How deep it goes
Explains bounded storage, append behavior, input buffering, and redraw callbacks, but does not discuss implementation internals.
Examples
Uses a scrolling message display, a character input buffer, a MessageStore, and an asynchronous delay console.
What you can do after
Apply it via Python's collections.deque to build bounded message stores and scrolling console output.
How it connects
Connects deques with terminal output, input buffering, coroutines, and asynchronous applications.

Also explained in

Compare how 3 books explain deque →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.