xmlrpc_extended.server¶
Core server classes and data types.
ThreadPoolXMLRPCServer¶
ThreadPoolXMLRPCServer ¶
ThreadPoolXMLRPCServer(addr: tuple[str, int], requestHandler: type[SimpleXMLRPCRequestHandler] = LimitedXMLRPCRequestHandler, logRequests: bool = True, allow_none: bool = False, encoding: str | None = None, bind_and_activate: bool = True, use_builtin_types: bool = False, *, max_workers: int = max_workers, max_pending: int | None = max_pending, request_queue_size: int = request_queue_size, overload_policy: ServerOverloadPolicy | str = BLOCK, max_request_size: int = max_request_size, overload_fault_code: int = overload_fault_code, overload_fault_string: str = overload_fault_string, rpc_paths: tuple[str, ...] | None = None, connection_timeout: float | None = None)
Bases: SimpleXMLRPCServer
A drop-in XML-RPC server that dispatches requests through a thread pool.
Replaces SimpleXMLRPCServer's single-threaded request handling with a
ThreadPoolExecutor and an explicit semaphore so that concurrency and
pending request depth are both bounded.
The constructor is fully compatible with SimpleXMLRPCServer and adds
keyword-only parameters for concurrency control, overload policy, and
request size limiting.
Example
from xmlrpc_extended import ServerOverloadPolicy, ThreadPoolXMLRPCServer
server = ThreadPoolXMLRPCServer(
("127.0.0.1", 8000),
max_workers=8,
max_pending=16,
overload_policy=ServerOverloadPolicy.HTTP_503,
logRequests=False,
)
server.register_function(lambda a, b: a + b, "add")
server.serve_forever()
Initialise the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
tuple[str, int]
|
|
required |
requestHandler
|
type[SimpleXMLRPCRequestHandler]
|
Request handler class. Defaults to
|
LimitedXMLRPCRequestHandler
|
logRequests
|
bool
|
Whether to log each request to stderr. |
True
|
allow_none
|
bool
|
Whether |
False
|
encoding
|
str | None
|
XML encoding; |
None
|
bind_and_activate
|
bool
|
If |
True
|
use_builtin_types
|
bool
|
Map XML-RPC |
False
|
max_workers
|
int
|
Maximum number of requests executing concurrently in the thread pool. Must be ≥ 1. |
max_workers
|
max_pending
|
int | None
|
Maximum number of additional requests that may queue
while all workers are busy. |
max_pending
|
request_queue_size
|
int
|
OS-level TCP accept backlog size. Controls how many connections the kernel will hold before refusing new ones. |
request_queue_size
|
overload_policy
|
ServerOverloadPolicy | str
|
What to do when total capacity is exhausted.
Accepts a |
BLOCK
|
max_request_size
|
int
|
Maximum accepted request body in bytes (default 1 MiB).
Requests larger than this receive |
max_request_size
|
overload_fault_code
|
int
|
XML-RPC fault code returned when
|
overload_fault_code
|
overload_fault_string
|
str
|
XML-RPC fault string returned when
|
overload_fault_string
|
rpc_paths
|
tuple[str, ...] | None
|
Accepted URL paths. |
None
|
connection_timeout
|
float | None
|
Per-connection socket read timeout in seconds.
After a client socket is accepted, this timeout is applied so
that a slow or stalled sender cannot hold a worker thread
indefinitely. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/xmlrpc_extended/server.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
stats ¶
stats() -> ServerStats
Return a point-in-time snapshot of server activity counters.
Thread-safe; acquires the internal stats lock for the duration of the snapshot copy. Safe to call from any thread, including from registered RPC methods.
Returns:
| Type | Description |
|---|---|
ServerStats
|
A |
ServerStats
|
moment of the call. |
Source code in src/xmlrpc_extended/server.py
submit_request ¶
Submit a request to the worker pool.
ServerOverloadPolicy¶
ServerOverloadPolicy ¶
Bases: str, Enum
How the server reacts when no worker capacity is available.
Members
BLOCK: Block the accept thread until a worker slot opens. No
request is ever actively rejected; excess connections queue at
the OS TCP backlog level.
CLOSE: Close the connection immediately without sending a response.
The client receives a connection-reset error.
FAULT: Return an XML-RPC 200 OK response containing a fault
element with the configured overload_fault_code and
overload_fault_string.
HTTP_503: Return an HTTP 503 Service Unavailable response with
a Retry-After: 1 header.
ServerStats¶
ServerStats
dataclass
¶
ServerStats(active: int, queued: int, rejected_close: int, rejected_fault: int, rejected_503: int, completed: int, errored: int)
Immutable point-in-time snapshot of server activity counters.
Returned by ThreadPoolXMLRPCServer.stats(). All fields are
non-negative integers. Counters (rejected_*, completed,
errored) are cumulative since the server started.
Attributes:
| Name | Type | Description |
|---|---|---|
active |
int
|
Requests currently executing in worker threads. |
queued |
int
|
Requests submitted to the thread pool but not yet started. |
rejected_close |
int
|
Cumulative rejections via the |
rejected_fault |
int
|
Cumulative rejections via the |
rejected_503 |
int
|
Cumulative rejections via the |
completed |
int
|
Cumulative requests that finished (including those where the XML-RPC method raised an application exception — those are still sent as valid fault responses). |
errored |
int
|
Cumulative requests that failed with a transport-level error (e.g. broken socket after partial write). |
XMLRPCServerConfig¶
XMLRPCServerConfig
dataclass
¶
XMLRPCServerConfig(max_workers: int = 8, max_pending: int | None = None, request_queue_size: int = 64, overload_policy: ServerOverloadPolicy = BLOCK, max_request_size: int = 1048576, overload_fault_code: int = -32500, overload_fault_string: str = 'Server overloaded', connection_timeout: float | None = None)
Resolved, validated configuration for ThreadPoolXMLRPCServer.
Created internally from the constructor arguments. Access it via
server.config to inspect the active settings.
Attributes:
| Name | Type | Description |
|---|---|---|
max_workers |
int
|
Maximum concurrent worker threads. |
max_pending |
int | None
|
Maximum requests queued beyond the active pool
( |
request_queue_size |
int
|
OS-level TCP accept backlog. |
overload_policy |
ServerOverloadPolicy
|
Active overload policy enum member. |
max_request_size |
int
|
Maximum body size in bytes. |
overload_fault_code |
int
|
XML-RPC fault code for the |
overload_fault_string |
str
|
XML-RPC fault string for the |