handling keyboard interupt and exiting main thread safely

kindof related to #104
This commit is contained in:
Adam Saudagar 2023-02-15 12:38:47 +05:30
parent b6e543a9e3
commit 4e55c88629
2 changed files with 33 additions and 30 deletions

View File

@ -53,43 +53,46 @@ def initialize(window_to_hide):
helper.install_required_addons()
def on_gui_load(gui, finish_splash, logger):
finish_splash()
update_dialog.check_update(gui)
logger.connect(gui)
def main():
print("launching please wait...")
config.init()
if not check_eula():
return
finish_splash = splash.start()
logger = GuiLogger()
config.start_backup_scheduler()
active.init()
hotkey.init()
def on_gui_load():
finish_splash()
update_dialog.check_update(gui)
logger.connect(gui)
window_to_hide = win32gui.GetForegroundWindow()
bot = EngineEventHandler(lambda: gui)
gui = GUI(lambda: bot, on_gui_load)
gui = GUI(lambda: bot, lambda: on_gui_load(gui, finish_splash, logger))
window_to_hide = win32gui.GetForegroundWindow()
logger = GuiLogger()
hotkey.init()
active.init()
hotkey.start()
try:
config.init()
if not check_eula():
return
logging.info(f"Fishybot v{fishy.__version__}")
initialize(window_to_hide)
logging.info(f"Fishybot v{fishy.__version__}")
gui.start()
active.start()
finish_splash = splash.start()
config.start_backup_scheduler()
bot.start_event_handler() # main thread loop
initialize(window_to_hide)
hotkey.stop()
active.stop()
config.stop()
bot.stop()
hotkey.start()
gui.start()
active.start()
bot.start_event_handler() # main thread loop
except KeyboardInterrupt as e:
...
finally:
gui._destroyed = True
hotkey.stop()
active.stop()
config.stop()
bot.stop()
if __name__ == "__main__":

View File

@ -14,12 +14,12 @@ class active:
return
active._scheduler = EventScheduler()
active._scheduler.start()
logging.debug("active scheduler initialized")
@staticmethod
def start():
web.ping()
active._scheduler.start()
active._scheduler.enter_recurring(60, 1, web.ping)
logging.debug("active scheduler started")