我正在尝试按照本指南和示例中所述使用 SWMR,但提供的示例脚本似乎不起作用。 我正在使用
这就是我作为脚本运行的内容
a.py
。它只是每秒增加文件的长度
import h5py
import numpy as np
import time
f = h5py.File("swmr.h5", 'w', libver='latest')
arr = np.array([1,2,3,4])
dset = f.create_dataset("data", chunks=(2,), maxshape=(None,), data=arr)
f.swmr_mode = True
# Now it is safe for the reader to open the swmr.h5 file
for i in range(50):
new_shape = ((i+1) * len(arr), )
dset.resize( new_shape )
dset[i*len(arr):] = arr
dset.flush()
time.sleep(1)
# Notify the reader process that new data has been written
脚本
b.py
,只是读取文件并打印数据的长度。
import h5py
f = h5py.File("swmr.h5", 'r', libver='latest', swmr=True)
dset = f["data"]
while True:
dset.id.refresh()
shape = dset.shape
print( shape )
我让
a.py
运行,也运行 b.py
,但是,打印在屏幕上的数组的形状不会随着时间的推移而改变。
如果在保持 a.py
运行的同时,关闭 b.py
并再次运行它,它将显示一个新的、更大的数组形状,但与以前一样,它不会随着时间的推移而改变。
dset.id.refresh() => dset.refresh()