diff --git a/src/core/interface/gui.py b/src/core/interface/gui.py index 858f31a..77fb881 100644 --- a/src/core/interface/gui.py +++ b/src/core/interface/gui.py @@ -725,6 +725,8 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): def closeEvent(self, event: QCloseEvent): closehelper() event.accept() + from core.utils.general.shutdown import force_exit + force_exit() def eventFilter(self, obj, event): try: diff --git a/src/core/network/libtorrent_int.py b/src/core/network/libtorrent_int.py index 4ed623a..d19e4fb 100644 --- a/src/core/network/libtorrent_int.py +++ b/src/core/network/libtorrent_int.py @@ -6,6 +6,7 @@ import threading import libtorrent as lt from core.utils.data.state import state from core.utils.logging.logs import consoleLog +from core.utils.general.shutdown import shutdown_event global loop_running @@ -116,9 +117,12 @@ def dl_status_loop(): loop_running = False return - while state.active_downloads: + while state.active_downloads and not shutdown_event.is_set(): for magnet_uri, magnetdl in list(state.active_downloads.items()): - status = magnetdl.status() + try: + status = magnetdl.status() + except RuntimeError: + continue if status.state == lt.torrent_status.seeding and magnet_uri not in completed_set: consoleLog(f"Download completed: {status.name}") diff --git a/src/core/utils/general/shutdown.py b/src/core/utils/general/shutdown.py index 28ab513..1834f45 100644 --- a/src/core/utils/general/shutdown.py +++ b/src/core/utils/general/shutdown.py @@ -1,9 +1,10 @@ import threading -from core.network.libtorrent_misc import cleanup_session -from core.utils.general.wrappers import run_thread +import os shutdown_event = threading.Event() def closehelper(): - run_thread(threading.Thread(target=cleanup_session)) - shutdown_event.set() \ No newline at end of file + shutdown_event.set() + +def force_exit(): + os._exit(0) \ No newline at end of file diff --git a/src/main.py b/src/main.py index 72a2ec1..097f67d 100644 --- a/src/main.py +++ b/src/main.py @@ -33,7 +33,8 @@ def run_gui(): def keyboardinterrupthandler(signum, frame): closehelper() - windowCloseHelper() + from core.utils.general.shutdown import force_exit + force_exit() def main(): start_time = time.perf_counter()