From 442ef760355184a0a86ce31c7e2d8d478a0e5418 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Tue, 28 Nov 2023 17:22:05 -0300 Subject: [PATCH] [view.qt] fix: QT crash in case the file downloader thread is still alive --- bauh/view/qt/apps_table.py | 5 ++++- bauh/view/qt/thread.py | 3 +++ bauh/view/qt/window.py | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bauh/view/qt/apps_table.py b/bauh/view/qt/apps_table.py index 3e0b3700..9bacbefb 100644 --- a/bauh/view/qt/apps_table.py +++ b/bauh/view/qt/apps_table.py @@ -605,6 +605,9 @@ class PackagesTable(QTableWidget): self.file_downloader.signal_downloaded.connect(self._update_pkg_icon) self.file_downloader.start() - def stop_file_downloader(self) -> None: + def stop_file_downloader(self, wait: bool = False) -> None: if self.file_downloader: self.file_downloader.stop() + + if wait: + self.file_downloader.wait() diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py index 63a538a1..e1d99f36 100644 --- a/bauh/view/qt/thread.py +++ b/bauh/view/qt/thread.py @@ -1127,6 +1127,9 @@ class URLFileDownloader(QThread): self._stop = False def _get(self, url_: str, id_: Optional[object]): + if self._stop: + return + try: res = requests.get(url=url_, timeout=self._request_timeout) content = res.content if res.status_code == 200 else None diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 40d1e848..7358c5ff 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import List, Type, Set, Tuple, Optional, Dict, Any from PyQt5.QtCore import QEvent, Qt, pyqtSignal, QRect -from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QCursor +from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QCursor, QCloseEvent from PyQt5.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QHeaderView, QToolBar, \ QLabel, QPlainTextEdit, QProgressBar, QPushButton, QComboBox, QApplication, QListView, QSizePolicy, \ QMenu, QHBoxLayout @@ -1767,3 +1767,7 @@ class ManageWindow(QWidget): self.verify_warnings() self.types_changed = True self.begin_refresh_packages() + + def closeEvent(self, event: QCloseEvent) -> None: + # needs to be stopped to avoid a Qt exception/crash + self.table_apps.stop_file_downloader(wait=True)