Skip to content

Commit

Permalink
Make shutdown_socket optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Unrud committed Aug 31, 2020
1 parent 732f35b commit e7a5d03
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions radicale/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,16 @@ def handle(self):
handler.run(self.server.get_app())


def serve(configuration, shutdown_socket):
"""Serve radicale from configuration."""
def serve(configuration, shutdown_socket=None):
"""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")
# Copy configuration before modifying
configuration = configuration.copy()
Expand Down Expand Up @@ -270,7 +278,8 @@ def serve(configuration, shutdown_socket):
if max_connections <= 0 or len(rlist) < max_connections:
rlist.extend(servers)
# Use socket to get notified of program shutdown
rlist.append(shutdown_socket)
if shutdown_socket is not None:
rlist.append(shutdown_socket)
rlist, _, _ = select.select(rlist, [], [], select_timeout)
rlist = set(rlist)
if shutdown_socket in rlist:
Expand Down

0 comments on commit e7a5d03

Please sign in to comment.