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:
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user