-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
33 lines (27 loc) · 992 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import asyncio
import warnings
import logging
from contextlib import suppress
from bot.utils.launcher import process
from bot.utils import logger
logging.getLogger("asyncio").setLevel(logging.CRITICAL)
logging.getLogger("aiohttp").setLevel(logging.CRITICAL)
async def main():
try:
await process()
except KeyboardInterrupt as error:
await asyncio.sleep(delay=3)
await close_tasks()
async def close_tasks():
tasks = [t for t in asyncio.all_tasks() if not t.done()]
for task in tasks:
task.cancel()
await asyncio.gather(*tasks, return_exceptions=True)
if __name__ == '__main__':
with suppress(KeyboardInterrupt):
try:
asyncio.run(main())
except Exception as error:
logger.info(f"<magenta>Something went wrong. Script stopped</magenta>: <light-yellow>{error}</light-yellow>")
except KeyboardInterrupt as error:
logger.info("<magenta>Script stopped by user</magenta> 🐾")