【问题标题】:Syncing an hdf5 via Dropbox file as it's being written在写入时通过 Dropbox 文件同步 hdf5
【发布时间】:2017-06-24 07:28:41
【问题描述】:

我有一个如下所示的 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='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。

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

【问题讨论】:

标签: python dropbox hdf5 pytables


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 2020-07-24
    • 2016-12-24
    • 2014-08-01
    • 2022-07-07
    • 1970-01-01
    • 2022-07-06
    相关资源
    最近更新 更多