2017-06-22 44 views
0

我有一个python脚本,看起来像这样:正在同步通过Dropbox的文件的HDF5,因为它是被写入

#!/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_it_update_dropbox.h5,我可以使Dropbox同步。但是,我实验室的机器是Windows。

堆栈溢出,我如何通过Dropbox将HDF5文件同步写入Windows计算机中进行同步?

+1

如果你需要的是“触摸”的窗口,看看这个https://stackoverflow.com/questions/30011267/windows-equivalent-of-touch-ie-the-node-js-写一个小的Python脚本,比如'open(“does_it_update_dropbox.h5”,“ab”)。write(“”) – Pablo

回答

0

Pablo的回答是正确的,并且让我变成了一个更优雅的解决方案。

import os 
filename = "does_it_update_dropbox.h5" 
h5file.flush() 
os.stat(filename) # this does the magic of updating the filesize on the disk 
相关问题