liveBook · Manning

Thread-per-connection model

As explained in Python Concurrency with asyncio

The thread-per-connection model assigns a dedicated thread to each connected client or connection.

The thread-per-connection model handles blocking socket servers by assigning one thread to each connected client. The main thread accepts connections while each client thread repeatedly receives and sends data. section 7.1

A typical implementation follows this sequence:

  • Read from and write to the client inside that thread, allowing other clients to proceed independently. section 7.1

This approach lets blocking recv and sendall operations affect only their own client thread, but interruption and shutdown require explicit handling. A thread subclass can detect closed connections, catch socket errors, and send a shutdown message. section 7.1

How Python Concurrency with asyncio covers it

How deep it goes
Explains connection assignment, thread execution, blocking behavior, and shutdown handling without descending into thread internals.
Examples
Uses a multithreaded echo server, concurrent telnet clients, keyboard interruption, and a shutdown-aware thread subclass.
What it assumes
Requires basic socket-server operations; introduces per-client threading through a concrete echo-server workflow.
What you can do after
Build a concurrent blocking-socket echo server and improve its client-thread shutdown behavior.
How it connects
Connects blocking sockets with threads, the GIL, non-blocking sockets, and the select module.

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.