Skip to content

Commit

Permalink
Core: clean up MultiServer.py/auto_shutdown (ArchipelagoMW#2552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Berserker66 authored and Jouramie committed Feb 28, 2024
1 parent d4f65bc commit c9fb79f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,25 +2210,24 @@ def parse_args() -> argparse.Namespace:

async def auto_shutdown(ctx, to_cancel=None):
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():
if not ctx.client_activity_timers.values():
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.")
inactivity_shutdown()
else:
newest_activity = max(ctx.client_activity_timers.values())
delta = datetime.datetime.now(datetime.timezone.utc) - newest_activity
seconds = ctx.auto_shutdown - delta.total_seconds()
if seconds < 0:
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.")
inactivity_shutdown()
else:
await asyncio.sleep(seconds)

Expand Down

0 comments on commit c9fb79f

Please sign in to comment.