Skip to content

Commit 1d36374

Browse files
authored
Properly close file before next data opened (#360)
* Properly close file before next data opened * Do not use libver='latest', more compatible hdf5 file
1 parent e90a020 commit 1d36374

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
44

55
## [Unreleased]
66

7+
### Fixed
8+
- Properly close files prior to new data file creation (fix file inconsistency)
9+
- Do not use h5py libver="latest" (fix segfault upon copying)
10+
711
## [2021.1.0]
812

913
### Added

yaqc_cmds/somatic/_wt5.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313

1414
class DataContainer(object):
1515
def __init__(self):
16-
self.data = None
16+
self._data = None
1717
self.data_filepath = None
1818
self.last_idx_written = None
1919
self.lock = threading.RLock()
2020

2121
def __enter__(self):
2222
self.lock.acquire()
23-
return self.data
23+
if self.data_filepath:
24+
self._data = wt.open(self.data_filepath, edit_local=True)
25+
return self._data
2426

2527
def __exit__(self, exc_type, exc_value, traceback):
28+
if self._data:
29+
self._data.close()
30+
self._data = None
2631
self.lock.release()
2732

2833

@@ -49,14 +54,9 @@ def create_data(path, headers, destinations, axes, constants, hardware, sensors)
4954
sensors: list of yaqc_cmds._sensors.Sensor objects
5055
all active sensors
5156
"""
52-
f = h5py.File(path, "w", libver="latest")
57+
f = h5py.File(path, "w")
5358
global data_container
5459
with data_container as data:
55-
56-
if data_container.data is not None:
57-
data_container.data.close()
58-
data_container.data = None
59-
6060
data = wt.Data(f, name=headers["name"], edit_local=True)
6161
data_container.data_filepath = path
6262

@@ -150,7 +150,6 @@ def create_data(path, headers, destinations, axes, constants, hardware, sensors)
150150
# TODO signed?
151151
# TODO labels?
152152

153-
data_container.data = data
154153
somatic.signals.data_file_created.emit()
155154

156155

0 commit comments

Comments
 (0)