use atexit instead of error handling

This commit is contained in:
Mylloon 2023-04-03 04:20:35 +02:00
parent 7cac16642b
commit 87a92b095b
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

30
main.py
View file

@ -1,8 +1,22 @@
from atexit import register
from sys import argv
from threading import Thread
from cheat import Cheat, sleep
def do_on_exit():
"""Called when the program end"""
for fn in [c.cheats_list[i] for i in c_id]:
try:
unloader = getattr(c, f"{fn}_unload")
except:
pass
else:
print(f"Unload {fn}...")
unloader()
if __name__ == "__main__":
c_id = []
args = {}
@ -49,16 +63,8 @@ if __name__ == "__main__":
t.daemon = True
t.start()
register(do_on_exit)
# Don't close the main thread as cheats are daemons
try:
while True:
sleep(1000000)
except KeyboardInterrupt:
for fn in [c.cheats_list[i] for i in c_id]:
try:
unloader = getattr(c, f"{fn}_unload")
except:
pass
else:
print(f"Unload {fn}...")
unloader()
while True:
sleep(1000000)