python-neo
python-neo copied to clipboard
Make BasefromrawIO context manager
Such that all rawio implementation can be used like this:
with BlackrockIO('filename') as io:
io.read_block()
I don't think we can do this for 0.8. This would imply a BaseRaw._close mandatory method.
And so in BaseFromraw it would be trivial:
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
but but but
this ._close() must be added and tested for rawio to cleanly close all underlying memmap. It is too much work for now.
I propose to postpone to 0.9.0.
What would you except from:
with SomeIO(filename') as reader:
seg = reader.read_segment(lazy=True)
anasig = seg.analogsignals[0].load()
I think an error should be raise.
Most of RawIOs are memmap based so we would must test if the reader is closed or not at each get_analogsignal_chunk
. I don't known if it would penalize the read speed.
I +1'd the idea earlier, but these are good points @samuelgarcia.
Maybe this would help with the spikeinterface issue https://github.com/SpikeInterface/spikeinterface/issues/1234. Following on this.