-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcleanup.py
More file actions
34 lines (27 loc) · 1.22 KB
/
cleanup.py
File metadata and controls
34 lines (27 loc) · 1.22 KB
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
34
from imports import *
from bronxbot import *
# None of these functions are even called in your program, are they for the future?
def cleanup_resources():
"""Cleanup resources on shutdown"""
try: # Note: Why use a try catch statement here? if the if statement is false, it wouldn't throw an exception, would only ignore the statement entirely, the try catch is useless
if hasattr(bot, 'scalability_manager') and bot.scalability_manager:
asyncio.create_task(bot.scalability_manager.cleanup())
logging.info("Scalability manager cleanup initiated")
except:
pass
try:
usage_tracker.cleanup() # Maybe this might need a try catch, but not the other one
logging.info("Command tracker cleanup completed")
except:
pass
logging.info("Resource cleanup completed")
# Register cleanup handler
atexit.register(cleanup_resources)
def signal_handler(signum, frame):
"""Handle shutdown signals"""
logging.info(f"Received signal {signum}, shutting down gracefully...")
cleanup_resources()
sys.exit(0)
# Register signal handlers
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)