Skip to content

Commit

Permalink
Merge pull request #52 from ramenbytes/close-files-on-error
Browse files Browse the repository at this point in the history
Ensure h5file is closed even if validation fails
  • Loading branch information
harripd authored May 19, 2024
2 parents 3a86e58 + cb42325 commit 28488e6
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions phconvert/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,14 @@ def save_photon_hdf5(data_dict,
h5file.flush()

## Validation
if validate:
kwargs = dict(skip_measurement_specs=skip_measurement_specs,
warnings=warnings, require_setup=require_setup)
assert_valid_photon_hdf5(h5file, **kwargs)
if close:
h5file.close()
try:
if validate:
kwargs = dict(skip_measurement_specs=skip_measurement_specs,
warnings=warnings, require_setup=require_setup)
assert_valid_photon_hdf5(h5file, **kwargs)
finally:
if close:
h5file.close()


def _is_mutispot(h5root_or_dict):
Expand Down

0 comments on commit 28488e6

Please sign in to comment.