Add graceful exits

This sets up a set of ropes and pulleys that signal the `Bot.keepalive`
function to clean things up after a quit signal has been sent. This
allows plugins to define an `on_unload` function to save any important
datas on intentional exit.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-05-24 19:16:15 -07:00
parent ffb2d4204e
commit 82e50f86d6
3 changed files with 28 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
import asyncio
from functools import partial
import logging
import signal
from .config import ServerConfig
from .bot import Bot
@@ -10,15 +12,18 @@ logging.basicConfig(
)
log = logging.getLogger(__name__)
log.debug("Loading config")
config = ServerConfig()
config.load("config.toml")
log.debug("Using configuration: %s", config)
async def main():
log.debug("Loading config")
config = ServerConfig()
config.load("config.toml")
log.debug("Using configuration: %s", config)
bot = Bot(config)
server = Bot(config)
await server.run()
asyncio.run(main())
try:
asyncio.run(bot.run())
except KeyboardInterrupt:
log.info("Got ctrl-c")
finally:
log.info("Quitting, press ctrl-c to quit immediately")
bot.quit()
asyncio.run(bot.keepalive())