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