From 9af9994f83115aa95f424f2eb6ae5ebd6abbb62a Mon Sep 17 00:00:00 2001 From: Patrick Avery Date: Wed, 8 Jan 2025 11:14:43 -0600 Subject: [PATCH] Avoid nested functions in QueuedConnections The one in the indexing runner in particular was freezing the application starting in Qt 6.8.1. I'm not entirely sure why, but making the function a method on the class rather than making it a nested function appears to fix the issue. We'll just try to avoid using nested functions in Qt QueuedConnections. Signed-off-by: Patrick Avery --- hexrdgui/indexing/run.py | 20 ++++++++---- hexrdgui/rerun_clustering_dialog.py | 50 +++++++++++++++++++---------- 2 files changed, 46 insertions(+), 24 deletions(-) diff --git a/hexrdgui/indexing/run.py b/hexrdgui/indexing/run.py index 06ab7d1e9..5bef2cb76 100644 --- a/hexrdgui/indexing/run.py +++ b/hexrdgui/indexing/run.py @@ -323,15 +323,21 @@ def indexer_finished(self): worker = AsyncWorker(self.run_cluster_functions) self.thread_pool.start(worker) - def on_finished(): - # Since this is a QueuedConnection, we must accept the progress - # before proceeding. - self.accept_progress() - self.confirm_indexing_results() - - worker.signals.result.connect(on_finished, Qt.QueuedConnection) + worker.signals.result.connect(self._on_run_cluster_functions_finished, + Qt.QueuedConnection) worker.signals.error.connect(self.on_async_error) + def _on_run_cluster_functions_finished(self): + # This function was previously a nested function, but for some reason, + # in the latest version of Qt (Qt 6.8.1), a queued connection on a + # nested function no longer seems to work (the application freezes). + # It appears to work, however, if this is a method on the object. + + # Since this is a QueuedConnection, we must accept the progress + # before proceeding. + self.accept_progress() + self.confirm_indexing_results() + @property def clustering_needs_min_samples(self): # Determine whether we need the min_samples for clustering diff --git a/hexrdgui/rerun_clustering_dialog.py b/hexrdgui/rerun_clustering_dialog.py index 60db01262..155b026d0 100644 --- a/hexrdgui/rerun_clustering_dialog.py +++ b/hexrdgui/rerun_clustering_dialog.py @@ -84,28 +84,44 @@ def accept(self): worker = AsyncWorker(runner.run_cluster) runner.thread_pool.start(worker) - def on_finished(): - # Since this is a QueuedConnection, we need to accept progress here - runner.accept_progress() - runner.confirm_indexing_results() - - if runner.grains_table is None: - # The previous step must have failed. Show again. - QTimer.singleShot(0, self.exec) - - def on_rejected(): - # Since this is a QueuedConnection, we need to accept progress here - runner.accept_progress() - self.exec() - - worker.signals.result.connect(on_finished, Qt.QueuedConnection) - runner.indexing_results_rejected.connect(on_rejected, - Qt.QueuedConnection) + worker.signals.result.connect( + self._on_run_cluster_finished, + Qt.QueuedConnection, + ) + runner.indexing_results_rejected.connect( + self._on_indexing_results_rejected, + Qt.QueuedConnection, + ) worker.signals.error.connect(runner.on_async_error) runner.progress_dialog.exec() super().accept() + def _on_run_cluster_finished(self): + # This function was previously a nested function, but for some reason, + # in the latest version of Qt (Qt 6.8.1), a queued connection on a + # nested function no longer seems to work (the application freezes). + # It appears to work, however, if this is a method on the object. + runner = self.indexing_runner + + # Since this is a QueuedConnection, we need to accept progress here + runner.accept_progress() + runner.confirm_indexing_results() + + if runner.grains_table is None: + # The previous step must have failed. Show again. + QTimer.singleShot(0, self.exec) + + def _on_indexing_results_rejected(self): + # This function was previously a nested function, but for some reason, + # in the latest version of Qt (Qt 6.8.1), a queued connection on a + # nested function no longer seems to work (the application freezes). + # It appears to work, however, if this is a method on the object. + + # Since this is a QueuedConnection, we need to accept progress here + self.indexing_runner.accept_progress() + self.exec() + def exec(self): self.setup_gui() self.ui.exec()