Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid nested functions in QueuedConnections #1770

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions hexrdgui/indexing/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 33 additions & 17 deletions hexrdgui/rerun_clustering_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Loading