Refactor: enhance AppDaemons with QThread for improved background task management

This commit is contained in:
Vxrtrauter
2026-04-14 14:40:19 +02:00
parent 7310049246
commit 392d2a6f03
2 changed files with 11 additions and 5 deletions
+6 -2
View File
@@ -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,)))
+5 -3
View File
@@ -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):