Core: clean up MultiServer.py/auto_shutdown (#2552)
This commit is contained in:
parent
f22daca74e
commit
70fdd6b90d
|
@ -2210,25 +2210,24 @@ def parse_args() -> argparse.Namespace:
|
||||||
|
|
||||||
async def auto_shutdown(ctx, to_cancel=None):
|
async def auto_shutdown(ctx, to_cancel=None):
|
||||||
await asyncio.sleep(ctx.auto_shutdown)
|
await asyncio.sleep(ctx.auto_shutdown)
|
||||||
|
|
||||||
|
def inactivity_shutdown():
|
||||||
|
ctx.server.ws_server.close()
|
||||||
|
ctx.exit_event.set()
|
||||||
|
if to_cancel:
|
||||||
|
for task in to_cancel:
|
||||||
|
task.cancel()
|
||||||
|
logging.info("Shutting down due to inactivity.")
|
||||||
|
|
||||||
while not ctx.exit_event.is_set():
|
while not ctx.exit_event.is_set():
|
||||||
if not ctx.client_activity_timers.values():
|
if not ctx.client_activity_timers.values():
|
||||||
ctx.server.ws_server.close()
|
inactivity_shutdown()
|
||||||
ctx.exit_event.set()
|
|
||||||
if to_cancel:
|
|
||||||
for task in to_cancel:
|
|
||||||
task.cancel()
|
|
||||||
logging.info("Shutting down due to inactivity.")
|
|
||||||
else:
|
else:
|
||||||
newest_activity = max(ctx.client_activity_timers.values())
|
newest_activity = max(ctx.client_activity_timers.values())
|
||||||
delta = datetime.datetime.now(datetime.timezone.utc) - newest_activity
|
delta = datetime.datetime.now(datetime.timezone.utc) - newest_activity
|
||||||
seconds = ctx.auto_shutdown - delta.total_seconds()
|
seconds = ctx.auto_shutdown - delta.total_seconds()
|
||||||
if seconds < 0:
|
if seconds < 0:
|
||||||
ctx.server.ws_server.close()
|
inactivity_shutdown()
|
||||||
ctx.exit_event.set()
|
|
||||||
if to_cancel:
|
|
||||||
for task in to_cancel:
|
|
||||||
task.cancel()
|
|
||||||
logging.info("Shutting down due to inactivity.")
|
|
||||||
else:
|
else:
|
||||||
await asyncio.sleep(seconds)
|
await asyncio.sleep(seconds)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue