Skip to content

Commit

Permalink
Merge pull request microsoft#1455 from VandersypenQutech/fix/hdf5
Browse files Browse the repository at this point in the history
add flush option to hdf5 write_metadata
  • Loading branch information
astafan8 authored Feb 11, 2019
2 parents 67d0c83 + ff16f88 commit bec01dc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
4 changes: 4 additions & 0 deletions qcodes/data/hdf5_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ def write_metadata(self, data_set, io_manager=None, location=None, read_first=Tr
metadata_group = data_set._h5_base_group.create_group('metadata')
self.write_dict_to_hdf5(data_set.metadata, metadata_group)

# flush ensures buffers are written to disk
# (useful for ensuring openable by other files)
data_set._h5_base_group.file.flush()

def _read_list_group(self, entry_point, list_type):
d = {}
self.read_dict_from_hdf5(data_dict=d,
Expand Down
14 changes: 2 additions & 12 deletions qcodes/tests/test_hdf5formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,10 @@ def test_dataset_closing(self):
data = DataSet1D(location=self.loc_provider, name='test_closing')
self.formatter.write(data, flush=False)
fp = data._h5_base_group.filename
fp2 = fp[:-5]+'_2.hdf5'
copy(fp, fp2)
# Raises an error because the file was open and not flushed
# This tests if this way of testing works
with self.assertRaises(OSError):
F2 = h5py.File(fp2)
self.formatter.close_file(data)
fp3 = fp[:-5]+'_3.hdf5'
copy(fp, fp3)
# Should now not raise an error because the file was properly closed
# Should not raise an error because the file was properly closed
F3 = h5py.File(fp3)

def test_dataset_flush_after_write(self):
Expand All @@ -244,11 +238,7 @@ def test_dataset_finalize_closes_file(self):
# closing before file is written should not raise error
self.formatter.write(data, flush=False)
fp = data._h5_base_group.filename
fp2 = fp[:-5]+'_2.hdf5'
copy(fp, fp2)
# Raises an error because the file was still open
with self.assertRaises(OSError):
F2 = h5py.File(fp2)

# Attaching the formatter like this should not be neccesary
data.formatter = self.formatter
data.finalize()
Expand Down

0 comments on commit bec01dc

Please sign in to comment.