Fixed core dumped on close

This commit is contained in:
Ignacio Serantes
2026-04-01 08:48:06 +02:00
parent 2fbf04fdb8
commit ae00235db8
6 changed files with 52 additions and 8 deletions

View File

@@ -34,7 +34,7 @@ from itertools import groupby
from PySide6.QtWidgets import (
QApplication, QMainWindow, QWidget, QLabel, QVBoxLayout, QHBoxLayout, QLineEdit,
QTextEdit, QPushButton, QFileDialog, QComboBox, QSlider, QMessageBox, QSizePolicy,
QMenu, QInputDialog, QTableWidget, QTableWidgetItem, QHeaderView, QTabWidget,
QMenu, QInputDialog, QTableWidget, QTableWidgetItem, QHeaderView, QTabWidget, QProgressDialog,
QDockWidget, QAbstractItemView, QRadioButton, QButtonGroup, QListView,
QStyledItemDelegate, QStyle, QDialog, QKeySequenceEdit, QDialogButtonBox
)
@@ -2010,6 +2010,9 @@ class MainWindow(QMainWindow):
def perform_shutdown(self):
"""Performs cleanup operations before the application closes."""
if getattr(self, '_is_shutting_down', False):
return
self._is_shutting_down = True
self.is_cleaning = True
# Save configuration early if visible, as per user request.
@@ -2017,6 +2020,24 @@ class MainWindow(QMainWindow):
if self.isVisible():
self.save_config()
# Stop all pending UI timers to prevent background tasks from triggering
self.hide_progress_timer.stop()
self.filter_input_timer.stop()
self.filter_refresh_timer.stop()
self.thumbnails_refresh_timer.stop()
self.rebuild_timer.stop()
self._model_update_timer.stop()
self.resume_scan_timer.stop()
# Close all viewers first to stop their preloader threads
self.close_all_viewers()
# Close duplicate manager if open to stop its preloader threads
if HAVE_IMAGEHASH:
for widget in QApplication.topLevelWidgets():
if isinstance(widget, DuplicateManagerDialog):
widget.close()
self.fs_watcher.stop()
# 1. Stop all worker threads interacting with the cache
@@ -2053,7 +2074,19 @@ class MainWindow(QMainWindow):
# Ensure all QRunnables in the shared thread pool are finished
if self.thread_pool_manager:
self.thread_pool_manager.get_pool().waitForDone()
pool = self.thread_pool_manager.get_pool()
if pool.activeThreadCount() > 0:
progress = QProgressDialog(UITexts.SHUTTING_DOWN, None, 0, 0, self)
progress.setWindowTitle(PROG_NAME)
progress.setWindowModality(Qt.ApplicationModal)
progress.setMinimumDuration(0)
progress.show()
# Wait in small increments to keep the UI responsive
while not pool.waitForDone(100):
if QApplication.instance():
QApplication.processEvents()
progress.close()
if self.duplicate_cache:
self.duplicate_cache.lmdb_close()