[view.qt] fix: QT crash in case the file downloader thread is still alive

This commit is contained in:
Vinicius Moreira
2023-11-28 17:22:05 -03:00
parent 656661b7b8
commit 442ef76035
3 changed files with 12 additions and 2 deletions

View File

@@ -605,6 +605,9 @@ class PackagesTable(QTableWidget):
self.file_downloader.signal_downloaded.connect(self._update_pkg_icon) self.file_downloader.signal_downloaded.connect(self._update_pkg_icon)
self.file_downloader.start() self.file_downloader.start()
def stop_file_downloader(self) -> None: def stop_file_downloader(self, wait: bool = False) -> None:
if self.file_downloader: if self.file_downloader:
self.file_downloader.stop() self.file_downloader.stop()
if wait:
self.file_downloader.wait()

View File

@@ -1127,6 +1127,9 @@ class URLFileDownloader(QThread):
self._stop = False self._stop = False
def _get(self, url_: str, id_: Optional[object]): def _get(self, url_: str, id_: Optional[object]):
if self._stop:
return
try: try:
res = requests.get(url=url_, timeout=self._request_timeout) res = requests.get(url=url_, timeout=self._request_timeout)
content = res.content if res.status_code == 200 else None content = res.content if res.status_code == 200 else None

View File

@@ -6,7 +6,7 @@ from pathlib import Path
from typing import List, Type, Set, Tuple, Optional, Dict, Any from typing import List, Type, Set, Tuple, Optional, Dict, Any
from PyQt5.QtCore import QEvent, Qt, pyqtSignal, QRect 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, \ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QCheckBox, QHeaderView, QToolBar, \
QLabel, QPlainTextEdit, QProgressBar, QPushButton, QComboBox, QApplication, QListView, QSizePolicy, \ QLabel, QPlainTextEdit, QProgressBar, QPushButton, QComboBox, QApplication, QListView, QSizePolicy, \
QMenu, QHBoxLayout QMenu, QHBoxLayout
@@ -1767,3 +1767,7 @@ class ManageWindow(QWidget):
self.verify_warnings() self.verify_warnings()
self.types_changed = True self.types_changed = True
self.begin_refresh_packages() 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)