Module

accept_distributor

AcceptDistributor — single-thread accept feeding a shared worker queue.

Eliminates thundering herd on macOS/Windows where SO_REUSEPORT is unavailable. One thread accepts connections and enqueues them into a single shared queue from which all SyncWorkers pull.

Classes

AcceptDistributor 2
Single thread that accepts connections and feeds a shared queue. Used when SO_REUSEPORT is unavail…

Single thread that accepts connections and feeds a shared queue.

Used when SO_REUSEPORT is unavailable (macOS, Windows). Avoids thundering herd where all workers block on accept() on the same fd.

All SyncWorkers pull from the same shared queue so the first idle worker handles the next connection — no head-of-line blocking.

Methods

run 0
Accept connections and enqueue for workers until shutdown.
def run(self) -> None
Internal Methods 1
__init__ 4
def __init__(self, sock: socket.socket, conn_queue: queue.Queue[tuple[socket.socket, object]], *, shutdown_event: threading.Event | None = None, ssl_context: ssl.SSLContext | None = None) -> None
Parameters
Name Type Description
sock
conn_queue
shutdown_event Default:None
ssl_context Default:None

Functions

is_shared_socket 1 bool
True if all workers share the same socket (no SO_REUSEPORT).
def is_shared_socket(sockets: list[socket.socket]) -> bool
Parameters
Name Type Description
sockets list[socket.socket]
Returns
bool