mirror of
https://github.com/aclist/dztui.git
synced 2026-08-26 09:47:36 +02:00
feat: set exit event on SIGINT
This commit is contained in:
parent
90f818f462
commit
0aafe44b4e
@ -1,7 +1,7 @@
|
||||
import inspect
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from typing import Any, Callable, TYPE_CHECKING
|
||||
from typing import Any, TYPE_CHECKING
|
||||
|
||||
import dzgui.util._json as JSON # noqa
|
||||
|
||||
@ -84,6 +84,8 @@ class Controller(GObject.GObject):
|
||||
self.loaded = False
|
||||
self.pending_jobs = 1
|
||||
|
||||
self.exit_event = threading.Event()
|
||||
|
||||
def get_emitter(self) -> Emitter:
|
||||
return self.emitter
|
||||
|
||||
@ -442,3 +444,9 @@ class Controller(GObject.GObject):
|
||||
|
||||
def get_modtreeview(self) -> "ModTreeView":
|
||||
return self.mediator.modtreeview
|
||||
|
||||
def set_exit_event(self) -> None:
|
||||
self.exit_event.set()
|
||||
|
||||
def get_exit_event(self) -> None:
|
||||
return self.exit_event
|
||||
|
||||
@ -91,6 +91,12 @@ class ServerModelManager:
|
||||
futures = [executor.submit(job, key, APPID_DAYZ, param) for param in params]
|
||||
for future in as_completed(futures):
|
||||
try:
|
||||
|
||||
# NOTE: faciliate early aborting on boot via sigint
|
||||
# this logic not available outside of initial boot
|
||||
if self.controller.get_exit_event().is_set():
|
||||
return
|
||||
|
||||
self.thread_man.increment_dialog()
|
||||
res = future.result(timeout=API_TIMEOUT)
|
||||
if res.status != 200 or not res.parsed:
|
||||
@ -101,7 +107,6 @@ class ServerModelManager:
|
||||
j = res.json
|
||||
servers += j["response"]["servers"]
|
||||
except Exception as e:
|
||||
# TODO: could store exception in cleanup func
|
||||
logger.critical(e)
|
||||
self.thread_man.set_cleanup_func(
|
||||
StoredFunc(self._cleanup_on_failure)
|
||||
|
||||
@ -94,7 +94,6 @@ class OuterWindow(Gtk.Window):
|
||||
self.halt_proc_and_quit()
|
||||
|
||||
def halt_proc_and_quit(self) -> None:
|
||||
# MainController.terminate_process()
|
||||
MainController.save_res_and_quit()
|
||||
|
||||
|
||||
@ -319,6 +318,7 @@ class App(Gtk.Application):
|
||||
logger.critical(e)
|
||||
|
||||
def _catch_sigint(self) -> Literal[True]:
|
||||
MainController.set_exit_event()
|
||||
self.win.halt_proc_and_quit()
|
||||
return True
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user