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

Circumvent error arising from calling GUI function outside of GUI thread #491

Merged
merged 3 commits into from
Jun 19, 2023

Conversation

zacsimile
Copy link
Collaborator

The update_event thread makes GUI calls outside of main Tk loop, This results in

Traceback (most recent call last):
  File "C:\Users\DeanLab\.conda\envs\ASLM\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\DeanLab\.conda\envs\ASLM\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "c:\users\deanlab\desktop\github\aslm\src\aslm\controller\controller.py", line 953, in update_event
    self.update_stage_controller_silent(value)
  File "c:\users\deanlab\desktop\github\aslm\src\aslm\controller\controller.py", line 918, in update_stage_controller_silent
    self.stage_controller.set_position_silent(stage_gui_dict)
  File "c:\users\deanlab\desktop\github\aslm\src\aslm\controller\sub_controllers\stage_controller.py", line 306, in set_position_silent
    self.unbind_position_callbacks()
  File "c:\users\deanlab\desktop\github\aslm\src\aslm\controller\sub_controllers\stage_controller.py", line 250, in unbind_position_callbacks
    self.widget_vals[axis].trace_remove("write", cbname)
  File "C:\Users\DeanLab\.conda\envs\ASLM\lib\tkinter\__init__.py", line 424, in trace_remove
    self._tk.call('trace', 'remove', 'variable',
RuntimeError: main thread is not in main loop

from time to time. The right solution is to move all GUI calls out of external threads. The solution I propose here works around the threading so we have to change less code.

@AdvancedImagingUTSW
Copy link
Collaborator

“ # ZM: I am so sorry for this.”
😂

@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #491 (6450a5a) into develop (7c97070) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@             Coverage Diff             @@
##           develop     #491      +/-   ##
===========================================
- Coverage    47.00%   46.98%   -0.03%     
===========================================
  Files          155      155              
  Lines        14335    14342       +7     
===========================================
  Hits          6738     6738              
- Misses        7597     7604       +7     
Flag Coverage Δ
unittests 46.98% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/aslm/controller/controller.py 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Collaborator

@AdvancedImagingUTSW AdvancedImagingUTSW left a comment

Choose a reason for hiding this comment

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

What would happen in the case that it tries to update the stage controller silently 10 times, and it throws a RuntimeError each time?

@zacsimile
Copy link
Collaborator Author

The stage controller wouldn't update. So we'd have a mismatch between true stage position and what is reported in the program.

@zacsimile zacsimile merged commit 396522c into develop Jun 19, 2023
1 check passed
@AdvancedImagingUTSW AdvancedImagingUTSW deleted the tk-thread-fix branch December 15, 2023 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants