KeyboardInterrupt scan: corrupt lima file
Interrupting a scan (e.g. timescan) causes the lima HDF5 or EDF files to be corrupt sometimes. I only tried with the simulator. The HDF5 file is also locked indefinitely.
import gevent
import os
import h5py
from bliss.config import static
from bliss.common import scans
def test_scan(s, filefmt):
p = s.acq_chain.nodes_list[1].ctrl_params
p["saving_format"] = "HDF5"
p["saving_frame_per_file"] = 1000
p["saving_suffix"] = ".h5"
g = gevent.spawn(s.run)
if s.name == "timescan":
gevent.sleep(5)
try:
g.kill(KeyboardInterrupt)
except KeyboardInterrupt:
pass
gevent.sleep(1)
g.join()
filename = filefmt.format(scan_number=s.scan_number)
print(filename)
gevent.sleep(5) # increasing this time does not help
with h5py.File(filename, mode="r"):
pass
def get_detector():
config = static.get_config()
test_session = config.get("lima_test_session")
test_session.setup()
detector = test_session.env_dict["lima_simulator"]
scan_saving = test_session.scan_saving
filefmt = os.path.join(
scan_saving.get_path(),
scan_saving.images_path_template,
"lima_simulator_0000.h5",
)
return detector, filefmt
if __name__ == "__main__":
detector, filefmt = get_detector()
os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE"
while True:
# s = scans.loopscan(5, 0.1, detector, run=False)
s = scans.timescan(0.1, detector, run=False)
test_scan(s, filefmt)
This throws an exception on h5py.File
saying that the HDF5 file is locked (when HDF5_USE_FILE_LOCKING=TRUE) or corrupted (when HDF5_USE_FILE_LOCKING=FALSE). To clarify, this is the lima file, not the scan file.
/tmp/scans/lima_test_session/scan0001/lima_simulator_0000.h5
Traceback (most recent call last):
File "test.py", line 48, in <module>
test_scan(s, filefmt)
File "test.py", line 24, in test_scan
with h5py.File(filename, mode="r"):
File "/data/id21/inhouse/wout/dev/virtualenvs/rnice8/bliss/py37/lib/python3.7/site-packages/h5py/_hl/files.py", line 394, in __init__
swmr=swmr)
File "/data/id21/inhouse/wout/dev/virtualenvs/rnice8/bliss/py37/lib/python3.7/site-packages/h5py/_hl/files.py", line 170, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 85, in h5py.h5f.open
OSError: Unable to open file (bad object header version number)
Edited by Wout De Nolf