liveBook · Manning

Deadlock

As explained in Python Concurrency with asyncio

A deadlock is a state in which concurrent execution cannot progress because each participant waits indefinitely for a resource held by another participant or for an unreleased resource.

A deadlock is a standstill in which concurrent participants wait indefinitely for resources held by one another, so the application cannot progress. A self-wait on a non-reentrant lock is one example; conflicting lock-acquisition orders create another. section 7.3.2

Two locks, circular waiting

Suppose method a acquires lock A, pauses, and then requests lock B, while method b acquires B and requests A. Each thread now holds one lock and waits for the other; the program hangs forever. Listing 7.11 demonstrates this with Python threads, locks, and an intentional delay. section 7.3.2

Subprocess pipes and full buffers

A subprocess can deadlock when its piped output fills the stream-reader buffer. The child blocks while writing, and the parent blocks waiting for completion without consuming output. Consume the stream concurrently or use process.communicate(), as shown with a program producing one million lines. section 13.1.1

How Python Concurrency with asyncio covers it

How deep it goes
Works through lock-order and pipe-buffer mechanisms with runnable examples, while stopping short of formal deadlock conditions.
Examples
Demonstrates opposing lock orders, a million-line subprocess output, concurrent stream consumption, and communicate().
What it assumes
Assumes familiarity with concurrent threads, locks, asyncio subprocesses, and piped stream output.
What you can do after
Diagnose hangs by tracing circular lock ownership or unconsumed pipe output, then apply reentrant locks or communicate() where appropriate.
How it connects
Connects deadlocks with threads, locks, reentrant locks, asyncio, subprocesses, pipes, stream readers, and buffer management.

Also explained in

Compare how 15 books explain deadlock →

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.