use atexit instead of error handling
This commit is contained in:
parent
7cac16642b
commit
87a92b095b
1 changed files with 18 additions and 12 deletions
30
main.py
30
main.py
|
@ -1,8 +1,22 @@
|
||||||
|
from atexit import register
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
from cheat import Cheat, sleep
|
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__":
|
if __name__ == "__main__":
|
||||||
c_id = []
|
c_id = []
|
||||||
args = {}
|
args = {}
|
||||||
|
@ -49,16 +63,8 @@ if __name__ == "__main__":
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
|
register(do_on_exit)
|
||||||
|
|
||||||
# Don't close the main thread as cheats are daemons
|
# Don't close the main thread as cheats are daemons
|
||||||
try:
|
while True:
|
||||||
while True:
|
sleep(1000000)
|
||||||
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()
|
|
||||||
|
|
Reference in a new issue