Skip to content

Commit d21ff86

Browse files
authored
Merge pull request #1770 from HEXRD/remove-lambda-queued-connections
Avoid nested functions in QueuedConnections
2 parents dfc852f + 9af9994 commit d21ff86

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

hexrdgui/indexing/run.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,21 @@ def indexer_finished(self):
323323
worker = AsyncWorker(self.run_cluster_functions)
324324
self.thread_pool.start(worker)
325325

326-
def on_finished():
327-
# Since this is a QueuedConnection, we must accept the progress
328-
# before proceeding.
329-
self.accept_progress()
330-
self.confirm_indexing_results()
331-
332-
worker.signals.result.connect(on_finished, Qt.QueuedConnection)
326+
worker.signals.result.connect(self._on_run_cluster_functions_finished,
327+
Qt.QueuedConnection)
333328
worker.signals.error.connect(self.on_async_error)
334329

330+
def _on_run_cluster_functions_finished(self):
331+
# This function was previously a nested function, but for some reason,
332+
# in the latest version of Qt (Qt 6.8.1), a queued connection on a
333+
# nested function no longer seems to work (the application freezes).
334+
# It appears to work, however, if this is a method on the object.
335+
336+
# Since this is a QueuedConnection, we must accept the progress
337+
# before proceeding.
338+
self.accept_progress()
339+
self.confirm_indexing_results()
340+
335341
@property
336342
def clustering_needs_min_samples(self):
337343
# Determine whether we need the min_samples for clustering

hexrdgui/rerun_clustering_dialog.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,44 @@ def accept(self):
8484
worker = AsyncWorker(runner.run_cluster)
8585
runner.thread_pool.start(worker)
8686

87-
def on_finished():
88-
# Since this is a QueuedConnection, we need to accept progress here
89-
runner.accept_progress()
90-
runner.confirm_indexing_results()
91-
92-
if runner.grains_table is None:
93-
# The previous step must have failed. Show again.
94-
QTimer.singleShot(0, self.exec)
95-
96-
def on_rejected():
97-
# Since this is a QueuedConnection, we need to accept progress here
98-
runner.accept_progress()
99-
self.exec()
100-
101-
worker.signals.result.connect(on_finished, Qt.QueuedConnection)
102-
runner.indexing_results_rejected.connect(on_rejected,
103-
Qt.QueuedConnection)
87+
worker.signals.result.connect(
88+
self._on_run_cluster_finished,
89+
Qt.QueuedConnection,
90+
)
91+
runner.indexing_results_rejected.connect(
92+
self._on_indexing_results_rejected,
93+
Qt.QueuedConnection,
94+
)
10495
worker.signals.error.connect(runner.on_async_error)
10596
runner.progress_dialog.exec()
10697

10798
super().accept()
10899

100+
def _on_run_cluster_finished(self):
101+
# This function was previously a nested function, but for some reason,
102+
# in the latest version of Qt (Qt 6.8.1), a queued connection on a
103+
# nested function no longer seems to work (the application freezes).
104+
# It appears to work, however, if this is a method on the object.
105+
runner = self.indexing_runner
106+
107+
# Since this is a QueuedConnection, we need to accept progress here
108+
runner.accept_progress()
109+
runner.confirm_indexing_results()
110+
111+
if runner.grains_table is None:
112+
# The previous step must have failed. Show again.
113+
QTimer.singleShot(0, self.exec)
114+
115+
def _on_indexing_results_rejected(self):
116+
# This function was previously a nested function, but for some reason,
117+
# in the latest version of Qt (Qt 6.8.1), a queued connection on a
118+
# nested function no longer seems to work (the application freezes).
119+
# It appears to work, however, if this is a method on the object.
120+
121+
# Since this is a QueuedConnection, we need to accept progress here
122+
self.indexing_runner.accept_progress()
123+
self.exec()
124+
109125
def exec(self):
110126
self.setup_gui()
111127
self.ui.exec()

0 commit comments

Comments
 (0)