Python 通过Dropbox文件同步hdf5,因为它是';正在写什么
我有一个python脚本,如下所示:Python 通过Dropbox文件同步hdf5,因为它是';正在写什么,python,dropbox,hdf5,pytables,Python,Dropbox,Hdf5,Pytables,我有一个python脚本,如下所示: #!/usr/bin/env python3 import tables as pt import numpy as np import time class TestTable(pt.IsDescription): timestamp = pt.Float64Col() voltage = pt.Float32Col() h5file = pt.open_file('does_it_update_dropbox.h5', mode=
#!/usr/bin/env python3
import tables as pt
import numpy as np
import time
class TestTable(pt.IsDescription):
timestamp = pt.Float64Col()
voltage = pt.Float32Col()
h5file = pt.open_file('does_it_update_dropbox.h5', mode='a')
if not h5file.__contains__('/test'):
h5file.create_table('/', 'test', TestTable)
row = h5file.root.test.row
try:
while True:
time.sleep(10)
for _ in range(1000):
row['timestamp'] = time.time()
row['voltage'] = np.random.random(1)[0]
row.append()
h5file.root.test.flush()
print('1000 records added')
except:
pass
h5file.close()
每隔10秒,它将数据写入HDF5文件。比方说,我在实验室里有一台计算机,它在一夜之间从传感器收集数据,我想分析5英里外我家的数据。事实证明,如果这是在Dropbox监视的文件夹中,Dropbox只会在脚本完成后同步(比如,如果我给它一个键盘中断)。我发现,如果我在Unix机器上运行touch does\u it\u update\u Dropbox.h5
,我可以让Dropbox同步。然而,我实验室的机器是一台Windows
堆栈溢出,当HDF5文件在Windows计算机中写入时,如何使其通过Dropbox进行同步?的答案是正确的,并使我找到了一个更优雅的解决方案
import os
filename = "does_it_update_dropbox.h5"
h5file.flush()
os.stat(filename) # this does the magic of updating the filesize on the disk
如果您只需要在windows上使用“touch”,请查看一下,或者编写一个小型python脚本,如open(“does\it\u update\u dropbox.h5”、“ab”)。write(“”)