From 07994fb6b72b0c84d2ee2c69e5afdb204d33d5e6 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 14 Oct 2018 12:35:07 +0200 Subject: irc: Graceful bot shutdown Wait for remaining jobs to finish without accepting new ones, but still allow some interaction with the bot (status/revoke). --- crocoite/cli.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'crocoite/cli.py') diff --git a/crocoite/cli.py b/crocoite/cli.py index 55ff4a1..913db7c 100644 --- a/crocoite/cli.py +++ b/crocoite/cli.py @@ -125,6 +125,7 @@ def irc (): config.read (args.config) s = config['irc'] + loop = asyncio.get_event_loop() bot = Chromebot ( host=s.get ('host'), port=s.getint ('port'), @@ -134,7 +135,10 @@ def irc (): tempdir=s.get ('tempdir'), destdir=s.get ('destdir'), processLimit=s.getint ('process_limit'), - logger=logger) - bot.loop.create_task(bot.connect()) - bot.loop.run_forever() + logger=logger, + loop=loop) + stop = lambda signum: bot.cancel () + loop.add_signal_handler (signal.SIGINT, stop, signal.SIGINT) + loop.add_signal_handler (signal.SIGTERM, stop, signal.SIGTERM) + loop.run_until_complete(bot.run ()) -- cgit v1.2.3