xmlrpc_extended.multiprocess¶
Linux-only helpers for SO_REUSEPORT multi-process scale-out.
Linux only
This module raises OSError on non-Linux platforms.
create_reuseport_socket¶
create_reuseport_socket ¶
Create a TCP socket with SO_REUSEPORT enabled.
Multiple processes may call this function with the same host and port to share the listening socket. Each call creates an independent socket file descriptor bound to the same address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
The interface address to bind to (e.g. |
required |
port
|
int
|
The TCP port to listen on. |
required |
backlog
|
int
|
The OS-level accept backlog (default: 64). |
64
|
Returns:
| Type | Description |
|---|---|
socket
|
A bound, listening :class: |
Raises:
| Type | Description |
|---|---|
OSError
|
If |
Source code in src/xmlrpc_extended/multiprocess.py
spawn_workers¶
spawn_workers ¶
Spawn num_workers worker processes, each running worker_fn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker_fn
|
Callable[[], None]
|
A zero-argument callable that starts a server. Each
worker should call :func: |
required |
num_workers
|
int | None
|
Number of worker processes to start. Defaults to the number of available CPU cores. |
None
|
Returns:
| Type | Description |
|---|---|
list[Process]
|
List of started :class: |
list[Process]
|
is responsible for joining or terminating them. |
Example::
processes = spawn_workers(run_my_server, num_workers=4)
try:
for p in processes:
p.join()
except KeyboardInterrupt:
for p in processes:
p.terminate()