Make shutdown_socket optional
This commit is contained in:
parent
cd3fe3e73c
commit
46c39b28d6
@ -200,8 +200,16 @@ class RequestHandler(wsgiref.simple_server.WSGIRequestHandler):
|
|||||||
handler.run(self.server.get_app())
|
handler.run(self.server.get_app())
|
||||||
|
|
||||||
|
|
||||||
def serve(configuration, shutdown_socket):
|
def serve(configuration, shutdown_socket=None):
|
||||||
"""Serve radicale from configuration."""
|
"""Serve radicale from configuration.
|
||||||
|
|
||||||
|
`shutdown_socket` can be used to gracefully shutdown the server.
|
||||||
|
The socket can be created with `socket.socketpair()`, when the other socket
|
||||||
|
gets closed the server stops accepting new requests by clients and the
|
||||||
|
function returns after all active requests are finished.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
logger.info("Starting Radicale")
|
logger.info("Starting Radicale")
|
||||||
# Copy configuration before modifying
|
# Copy configuration before modifying
|
||||||
configuration = configuration.copy()
|
configuration = configuration.copy()
|
||||||
@ -270,6 +278,7 @@ def serve(configuration, shutdown_socket):
|
|||||||
if max_connections <= 0 or len(rlist) < max_connections:
|
if max_connections <= 0 or len(rlist) < max_connections:
|
||||||
rlist.extend(servers)
|
rlist.extend(servers)
|
||||||
# Use socket to get notified of program shutdown
|
# Use socket to get notified of program shutdown
|
||||||
|
if shutdown_socket is not None:
|
||||||
rlist.append(shutdown_socket)
|
rlist.append(shutdown_socket)
|
||||||
rlist, _, _ = select.select(rlist, [], [], select_timeout)
|
rlist, _, _ = select.select(rlist, [], [], select_timeout)
|
||||||
rlist = set(rlist)
|
rlist = set(rlist)
|
||||||
|
Loading…
Reference in New Issue
Block a user