fix: Race condition in the NapariLiveWidget for the new alignment feature - #461
Merged
Merged
Conversation
NapariLiveWidget was missing the is_switching_mode guard that LiveControlWidget has. During acquisition mode switches, this caused duplicate set_illumination() calls from two threads: 1. Worker thread calls set_microscope_mode() → update_illumination() 2. GUI thread receives signal → update_ui_for_mode() → slider.setValue() → valueChanged → update_config_illumination_intensity() → update_illumination() (DUPLICATE) Added is_switching_mode guard to NapariLiveWidget to prevent the duplicate MCU commands during mode switches. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
hongquanli
force-pushed
the
fix/napari-widget-illumination-race
branch
from
January 18, 2026 23:29
6ee6a3e to
49e0025
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
During multi-point acquisition, when the worker thread switches microscope modes, a race condition occurs:
signal_current_configuration(config)(Qt signal to GUI)set_microscope_mode(config)→ sends SET_ILLUMINATION cmdturn_on_illumination()→ sends TURN_ON_ILLUMINATION cmd (e.g., cmd 32)napariLiveWidget.update_ui_for_mode(config)valueChanged→update_config_illumination_intensity()update_illumination()→ sends duplicate SET_ILLUMINATION cmd (e.g., cmd 33)With two commands sent nearly simultaneously:
_cmd_idbecomes 33 (the last one assigned)From the log:
Solution
LiveControlWidgetalready has anis_switching_modeguard to prevent this.NapariLiveWidgetwas missing it.Added the same guard pattern to
NapariLiveWidget:is_switching_modeflag to constructorupdate_ui_for_mode()with try/finally to set/clear the flagupdate_config_illumination_intensity(),update_config_exposure_time(), andupdate_config_analog_gain()when flag is set🤖 Generated with Claude Code