pico-python
pico-python copied to clipboard
Fixing bug #180
Catch Exceptions in the _PicoscopeBase()
class (picobase.py) that are raised when not connected. They do not convey useful information, as they are typical error happening with the garbage collector and disappearing attributes.
I'm not sure i agree with the fix.
I think the issue is that:
https://github.com/colinoflynn/pico-python/blob/master/picoscope/ps5000a.py#L172
c_handle.value
could return 0x0
and not Null
. therefore we should be "checking" for that in the case of errors and handling that correctly.
That sure can be a source of error, which raises maybe an OSError. I 'll try to fix that too.
But the AttributeError
is very specific, and well documented. We actually should always call explicitly the close() method, and not rely on the __del__
method :
there is no guarantee that
__del__()
will be called: it's just for memory manager use, not for resource handling.
And after some testing, the real problem with the line you mention is that the next function is doing it's job, the close unit function raises after trying to connect to a given picoscope and failing. Actually, this happens :
- Try to open a picoscope,
_lowLevelOpenUnit
failing because it's not connected -
_lowLevelOpenUnit
function raises - The object is destroyed, calling
__del__
, callingclose()
, calling_lowLevelCloseUnit
-
_lowLevelCloseUnit
raises too becausec_handle.value
is wrong (for a good reason) since the beginning. And we ended up with two raised exception for one information (we're no connected), and that generates ignored exceptions in my code. The fix allow for the last raised exception to be truly ignored, and theAttributeError
one to never show up.