micro-manager / pymmcore

Python bindings for MMCore, Micro-Manager's device control layer
https://pypi.org/project/pymmcore/
GNU Lesser General Public License v2.1
32 stars 8 forks source link

Issue with error handling in `setSLMImage` #76

Closed ianhi closed 9 months ago

ianhi commented 1 year ago

Not sure if this belongs here in or in pymmcore but the following code crashes python:

from pymmcore import CMMCore
from pymmcore_plus import CMMCorePlus as CMMCore
core = CMMCore()
try:
    core.setSLMImage("nothing-loaded", "\x01"*512*512)
except Exception as e:
    print(repr(e))

print("did we get here?")

giving the following output:

terminate called after throwing an instance of 'CMMError'
  what():  No device with label "nothing-loaded"
Aborted (core dumped)

While I certainly expect an error to be thrown, I don't expect this cause python to crash, contrast with the same situation for snapImage:


from pymmcore import CMMCore
from pymmcore_plus import CMMCorePlus as CMMCore
core = CMMCore()
try:
    core.snapImage()
except Exception as e:
    print(repr(e))
    pass

print("did we get here?")

which gives:

RuntimeError('Camera not loaded or initialized.')
did we get here?
marktsuchida commented 1 year ago

Thanks. This looks like a pymmcore problem (the hand-written wrapper is not handling exceptions), so transferred.

marktsuchida commented 1 year ago

Although this is indeed a pymmcore, not MMCore, problem, it turns out that MMCoreJ has the exact same problem (not handling exceptions). So I filed micro-manager/mmCoreAndDevices#309 for that.

jdlamstein commented 1 year ago

Thanks for working on this guys.