cleanup and wait for child processes

This commit is contained in:
Unrud 2018-09-08 14:42:20 +02:00 committed by Unrud
parent db8a7302a0
commit 4fb851c80e

View File

@ -42,7 +42,7 @@ try:
except ImportError: except ImportError:
systemd = None systemd = None
if os.name == "posix": if hasattr(os, "fork"):
ParallelizationMixIn = socketserver.ForkingMixIn ParallelizationMixIn = socketserver.ForkingMixIn
else: else:
ParallelizationMixIn = socketserver.ThreadingMixIn ParallelizationMixIn = socketserver.ThreadingMixIn
@ -75,6 +75,9 @@ else:
class ParallelHTTPServer(ParallelizationMixIn, class ParallelHTTPServer(ParallelizationMixIn,
wsgiref.simple_server.WSGIServer): wsgiref.simple_server.WSGIServer):
# wait for child processes/threads
_block_on_close = True
# These class attributes must be set before creating instance # These class attributes must be set before creating instance
client_timeout = None client_timeout = None
max_connections = None max_connections = None
@ -311,8 +314,14 @@ def serve(configuration, shutdown_socket=None):
# Fallback to busy waiting. (select.select blocks SIGINT on Windows.) # Fallback to busy waiting. (select.select blocks SIGINT on Windows.)
select_timeout = 1.0 select_timeout = 1.0
logger.info("Radicale server ready") logger.info("Radicale server ready")
with contextlib.ExitStack() as stack:
for _, server in servers.items():
# close server
stack.push(server)
while True: while True:
rlist, _, xlist = select.select(sockets, [], sockets, select_timeout) rlist, _, xlist = select.select(
sockets, [], sockets, select_timeout)
if xlist: if xlist:
raise RuntimeError("unhandled socket error") raise RuntimeError("unhandled socket error")
if shutdown_socket in rlist: if shutdown_socket in rlist:
@ -322,3 +331,4 @@ def serve(configuration, shutdown_socket=None):
server = servers.get(rlist[0]) server = servers.get(rlist[0])
if server: if server:
server.handle_request() server.handle_request()
server.service_actions()