diff --git a/src/main.py b/src/main.py index 42b98a3..6a3f5f5 100644 --- a/src/main.py +++ b/src/main.py @@ -14,7 +14,7 @@ from utils.config.config import read_config from PySide6.QtGui import QAction, QPixmap from utils.logging.logs import consoleLog from interface.gui import MainWindow -from PySide6.QtCore import Qt, QObject +from PySide6.QtCore import Qt, QObject, QThread from utils.data.state import state from PySide6 import QtWidgets import qdarktheme @@ -142,8 +142,12 @@ def main(): init_interfaces() consoleLog(f"Current Bound: {state.bound_interface}") # Start background daemon threads + app._daemon_thread = QThread() app._daemons = AppDaemons() - app._daemons.start_all() + app._daemons.moveToThread(app._daemon_thread) + app._daemon_thread.started.connect(app._daemons.start_all) + app.aboutToQuit.connect(app._daemon_thread.quit) + app._daemon_thread.start() # Start background non-daemon threads run_thread(threading.Thread(target=check_completed, args=(downloads, state.autoresume))) run_thread(threading.Thread(target=check_downloads, args=(downloads,))) diff --git a/src/network/libtorrent_misc.py b/src/network/libtorrent_misc.py index 6b05e3e..72532e6 100644 --- a/src/network/libtorrent_misc.py +++ b/src/network/libtorrent_misc.py @@ -28,15 +28,17 @@ class AppDaemons(QObject): self.updated_magnets = set() # Create Timers - self.deleted_files_timer = QTimer() - self.completed_downloads_timer = QTimer() + self.deleted_files_timer = QTimer(self) + self.completed_downloads_timer = QTimer(self) # Connect Timer Signals self.deleted_files_timer.timeout.connect(self.check_deleted_files) self.completed_downloads_timer.timeout.connect(self.check_completed_downloads) def start_all(self): - self.deleted_files_timer.start(5000) + consoleLog("Starting Timer: deleted_files") + self.deleted_files_timer.start(2000) + consoleLog("Starting Timer: completed_downloads") self.completed_downloads_timer.start(5000) def check_deleted_files(self):