Closed tivek closed 5 years ago
Indeed this looks like a bad idea. At least the __del__
should be safe if the interface is closed. Could you implement the fix in gpib_ctypes and we could then switch to this implementation, since we do not win anything in using linux-gpib binding ?
I will merge sometimes this week since this is no matter what the sensible solution for now.
I will release gpib_ctypes that has close() as you suggest.
However, I would not rule out using linux-gpib.Gpib. I've pushed a second commit which patches in a close() method. I somehow feel it is important to support the original Python GPIB bindings since it has the largest user base. In the mean time I can ping the linux-gpib project and see if they would be willing to add close().
linux-gpib has merged a patch that introduces Gpib.close() like gpib_ctypes 0.2.0. Until it gets released, and to support users of older linux-gpib releases, I propose to keep the monkeypatching code from 5968788.
Sounds good. I agree that keeping the monkeypatch for now makes sense. Is this ready for merging ?
Ready for merging. Tested with linux-gpib r1767 (before the accepted patch), linux-gpib trunk as well as gpib_ctypes 0.2.0.
bors r+
I forgot to ask and I am going to fix it right away but in the future please update the release notes.
Sorry about the release notes, will do next time.
It is no big deal. I am just trying to keep the release notes up to date so that the release process is a bit more straightforward.
Fix a double close of GPIB connections which usually produces uncaught exceptions.
To reproduce the bug on pyvisa-py master:
Explanation and fix: GpibSession uses two Gpib.Gpib objects (linux-gpib project) to manage connections to the instrument and GPIB board. These clean up on their own in
__del__()
and we should not manually close their handles.Long-term,
__del__()
should not be used for reliable finalization since it is a potentially ugly implementation detail of CPython's GC. Sadly, Gpib.Gpib does not expose a better interface for cleanup. At some point we should either patch/fork Gpib.Gpib or switch to classic gpib function calls with integer handles.