Skip to content

fix: reset Cores created by the GUI when it closes - #168

Merged
tlambert03 merged 3 commits into
pymmcore-plus:mainfrom
gselzer:unload-on-close
Jul 19, 2026
Merged

tlambert03 merged 3 commits into
pymmcore-plus:mainfrom
gselzer:unload-on-close

Conversation

@gselzer

@gselzer gselzer commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Proper device shutdown requires calling CMMCore.reset() before terminating the application. This solution ensures that any CMMCore created by the application is reset before the main GUI closes.

Note that callers passing a CMMCore instance to MicroManagerGUI or create_mmgui are responsible for cleaning it up (they may want to continue using that instance after the GUI closes)

Proper device shutdown requires calling CMMCore.reset() before
terminating the application. This solution ensures that any CMMCore
created by the application is reset before the main GUI closes.

Note that callers passing a CMMCore instance to MicroManagerGUI or
create_mmgui are responsible for cleaning it up (they may want to
continue using that instance after the GUI closes)
@gselzer gselzer changed the title Reset Cores created by the GUI when it closes fix: reset Cores created by the GUI when it closes Jul 17, 2026
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.69%. Comparing base (3e40fed) to head (7601003).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #168      +/-   ##
==========================================
+ Coverage   81.87%   82.69%   +0.82%     
==========================================
  Files          29       29              
  Lines        1810     1815       +5     
==========================================
+ Hits         1482     1501      +19     
+ Misses        328      314      -14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03

Copy link
Copy Markdown
Member

I'm ok with this... but it smells a little bit like the thing we just spent a long time debugging (see pymmcore-plus/pymmcore-plus#572 and related issues).

this one is probably safer because it's a higher level object cleaning up the core... but, I'll point out that the C++ destructor of CMMCore itself calls reset. So, it's not strictly necessary for the user to call reset() (it's not the case that proper device shutdown always demands this). It's definitely possible that you found a race condition where object cleanup didn't happen or something, but can you confirm what you noticed that made you feel like this was necessary?

@gselzer

gselzer commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

It's definitely possible that you found a race condition where object cleanup didn't happen or something, but can you confirm what you noticed that made you feel like this was necessary?

@marktsuchida and I were testing a new device adapter on one of our scopes and found that devices were not being shutdown (specifically that (a) behavior programmed into shutdown was not being observed and (b) that no log messages relating to unloading devices were present in the core log) when we pressed the close button. Then I was able to replicate this on my own machine with the demo config.

Yeah, I was a bit suprised too that the CMMCore destructor does call this, but it's possible that with GUI shutdown behavior the C++ destructor doesn't get called in time?

@tlambert03

Copy link
Copy Markdown
Member

Arg. That's annoying :) I guess we'll just have to use belt and suspenders then

@tlambert03
tlambert03 merged commit 08beeb0 into pymmcore-plus:main Jul 19, 2026
15 checks passed
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