Issue 8506: SimpleXMLRPCServer Socket not closed after shutdown call (original) (raw)
Calling shutdown on a SimpleXMLRPCServer will stop the server but does not close the socket, meaning new connections to the same address will fail.
Example:
srv = SimpleXMLRPCServer((ip, port), logRequests=False, allow_none=True) srv.serve_forever(poll_interval=2)
srv.shutdown() is made available to the registered class instance.
The current workaround is to delete the socket (or call close() on the socket) after the server is shutdown, (i.e., "del srv.socket") but it seems this should be handled when the server is shutdown.
The behavior is as documented, so this is a feature request. The 3.1.2 doc in 20.19.2. Server Objects says "BaseServer.shutdown() Tells the serve_forever() loop to stop and waits until it does."
I presume this allows subsequent .handle_request() and ..serve_forever() calls, as well as others, so I think the request is a bad idea.
For automatic closing, use 'with' statements and a context manager and checkout contextlib. This is their main purpose.
I am not sure what "The server classes support the following class variables: BaseServer.allow_reuse_address Whether the server will allow the reuse of an address. This defaults to False, and can be set in subclasses to change the policy." or whether it would help you.