Merge pull request #404 from Unrud/patch-10

Use nonlocal instead of container
This commit is contained in:
Guillaume Ayoub 2016-05-21 02:20:12 +02:00
commit 8ebd3810b5

View File

@ -173,7 +173,7 @@ def run():
if not configuration.getboolean("server", "dns_lookup"): if not configuration.getboolean("server", "dns_lookup"):
RequestHandler.address_string = lambda self: self.client_address[0] RequestHandler.address_string = lambda self: self.client_address[0]
shutdown_program = [False] shutdown_program = False
for host in configuration.get("server", "hosts").split(","): for host in configuration.get("server", "hosts").split(","):
address, port = host.strip().rsplit(":", 1) address, port = host.strip().rsplit(":", 1)
@ -198,11 +198,12 @@ def run():
# SIGTERM and SIGINT (aka KeyboardInterrupt) should just mark this for # SIGTERM and SIGINT (aka KeyboardInterrupt) should just mark this for
# shutdown # shutdown
def shutdown(*args): def shutdown(*args):
if shutdown_program[0]: nonlocal shutdown_program
if shutdown_program:
# Ignore following signals # Ignore following signals
return return
logger.info("Stopping Radicale") logger.info("Stopping Radicale")
shutdown_program[0] = True shutdown_program = True
if shutdown_program_socket_in: if shutdown_program_socket_in:
shutdown_program_socket_in.sendall(b"goodbye") shutdown_program_socket_in.sendall(b"goodbye")
signal.signal(signal.SIGTERM, shutdown) signal.signal(signal.SIGTERM, shutdown)
@ -218,7 +219,7 @@ def run():
# Fallback to busy waiting # Fallback to busy waiting
select_timeout = 1.0 select_timeout = 1.0
logger.debug("Radicale server ready") logger.debug("Radicale server ready")
while not shutdown_program[0]: while not shutdown_program:
try: try:
rlist, _, xlist = select.select( rlist, _, xlist = select.select(
sockets, [], sockets, select_timeout) sockets, [], sockets, select_timeout)