python - Close an open h5py data file -
in our lab store our data in hdf5
files trough python package h5py
.
at beginning of experiment create hdf5
file , store array after array of array of data in file (among other things). when experiment fails or interrupted file not correctly closed. because our experiments run ipython
reference data object remains (somewhere) in memory.
is there way scan open h5py data objects , close them?
this how done (i not figure out how check closed-ness of file without exceptions, maybe find):
import gc obj in gc.get_objects(): # browse through objects if isinstance(obj, h5py.file): # hdf5 files try: obj.close() except: pass # closed
another idea:
dpending how use files, using context manager , with
keyword this?
with h5py.file("some_path.h5") f: f["data1"] = some_data
when program flow exits with-block, file closed regardless of happens, including exceptions etc.
Comments
Post a Comment