Python Sockets at Scale: I/O Multiplexing and Asyncio
summary
Shows that per-connection threads hit the GIL so they run concurrently not parallel, then demos using the OS readiness syscalls (select/poll/epoll/kqueue) and Python’s selectors module to multiplex sockets in one thread. Builds an echo server and a large-file sender where default blocking sockets stall other clients, switching sockets to non‑blocking yields partial writes you must track yourself, and asyncio Streams is presented as the layer that keeps per-connection pending buffers and uses writer.drain to flush reliably.
AI-written summary · about
chapters (23)
- 0:00Introduction
- 0:20What is I/O Multiplexing
- 1:46Synchronous vs threading approach
- 2:52Understanding the GIL
- 3:53Threading server demo
- 4:36Asyncio for true concurrency
- 5:21Sockets as file descriptors
- 6:46Blocking vs non-blocking I/O
- 7:52Non-blocking stdin with select
- 9:15File descriptor readiness
- 12:29Selectors API overview
- 13:35Non-blocking file descriptor monitoring
- 14:42Monitoring stdin and socket
- 15:47Select server demo
- 16:53Why use asyncio
- 17:57Select-based socket server
- 19:05Echo server demo
- 20:12Blocking socket issue
- 21:36Non-blocking sockets explained
- 23:01Socket buffer and blocking
- 24:51Pending data management
- 25:55Asyncio streams advantage
- 27:23Drain method in asyncio
