Skip to content

Run trajectory plots after analysis completes - #3466

Draft
C-Achard wants to merge 6 commits into
devfrom
cy/fix-plot-thread-gui-freeze
Draft

Run trajectory plots after analysis completes#3466
C-Achard wants to merge 6 commits into
devfrom
cy/fix-plot-thread-gui-freeze

Conversation

@C-Achard

Copy link
Copy Markdown
Collaborator

Store plotting options before starting the worker and defer plot_trajectories(showfigures=True) to a main-thread finished slot.

The analysis pipeline now always runs with showfigures=False, only opens trajectory plots when analysis succeeds, and centralizes button/progress-bar reset in the completion handler.

This fixes the GUI freezing due to plots opening in the wrong thread.

Closes #3462.

Store plotting options before starting the worker and defer `plot_trajectories(showfigures=True)` to a main-thread finished slot. The analysis pipeline now always runs with `showfigures=False`, only opens trajectory plots when analysis succeeds, and centralizes button/progress-bar reset in the completion handler.
@C-Achard C-Achard added this to the v3.1.0 milestone Aug 28, 2026
@C-Achard
C-Achard requested a lite review from Copilot August 28, 2026 11:43
@C-Achard C-Achard self-assigned this Aug 28, 2026
@C-Achard C-Achard added GUI issues relating to GUI bug fix labels Aug 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Analyze Videos GUI workflow to avoid GUI freezes by ensuring trajectory plots are only displayed from the main (GUI) thread after background analysis completes successfully.

Changes:

  • Stores plotting options/batches before launching the worker thread and defers interactive plotting to a finished-handler slot.
  • Forces the analysis pipeline to run plot_trajectories(..., showfigures=False) and only opens figures when analysis succeeds and the user requested plot display.
  • Centralizes UI reset (button/progress bar) in the completion handler.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread deeplabcut/gui/tabs/analyze_videos.py Outdated
Comment thread deeplabcut/gui/tabs/analyze_videos.py
@C-Achard C-Achard mentioned this pull request Aug 28, 2026
2 tasks
@deruyter92 deruyter92 added the 3.1 label Aug 28, 2026
@deruyter92
deruyter92 changed the base branch from main to dev August 31, 2026 09:40
Refactor post-analysis trajectory plot display to use a single-shot QTimer, ensuring the UI (button re-enable, progress bar hide) fully updates before plots are shown. Also fixes the `_handle_analysis_error` slot signature to accept the error argument, and adds error handling around trajectory plot display.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread deeplabcut/gui/tabs/analyze_videos.py
Update the Analyze Videos tab so `deeplabcut.plot_trajectories(...)` only runs when `plot_trajectories` is enabled and `show_trajectory_plots` is not. This prevents triggering the plotting routine in cases where trajectory plots are already being shown through the separate display flow.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Extract repeated None-assignment into `_clear_pending_trajectory_plots()` helper. Also move the button re-enable and progress bar hide after the plot timer/clear logic to ensure UI updates happen regardless of plot path.
@C-Achard
C-Achard marked this pull request as ready for review September 1, 2026 08:46
@C-Achard
C-Achard requested a review from deruyter92 September 1, 2026 08:46
@deruyter92 deruyter92 added 3.0.2 and removed 3.1 labels Sep 7, 2026

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good PR!

Just one remark about a behavioral change. Not sure how relevant it is, but worth having your explicit opinion.

Comment on lines +104 to +119
@Slot()
def _handle_analysis_finished(self):
should_show_plots = (
not self._analysis_failed
and self._pending_plot_options is not None
and self._pending_plot_batches is not None
and self._pending_plot_options.plot_trajectories
and self._pending_plot_options.show_trajectory_plots
)

self._analysis_failed = False

if should_show_plots:
self._pending_plot_timer.start()
else:
self._clear_pending_trajectory_plots()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One behavioral change:
This PR moves the plotting step from during successful batch processing to after the whole pipeline succeeds. Now, a late failure such as CSV conversion can suppress plots that otherwise would have been shown.

Do yo think this is justified or should we keep the previous behavior where plots are visualized as each batch succeeds?

@deruyter92 deruyter92 added 3.1 and removed 3.0.2 labels Sep 8, 2026

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after our discussion, we decided that this needs further changing ideally. To not change the existing behavior.

@deruyter92
deruyter92 marked this pull request as draft September 8, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.1 bug fix GUI issues relating to GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DLC Freezing Issue

3 participants