0

I have a python script that looks like this:

#!/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()

Every 10 seconds, it writes data to an HDF5 file. Let's say that I have a computer in a lab that's gathering data from a sensor overnight, and I'd like to analyze that data from my home 5 miles away. It turns out that if this is in a folder that is watched by Dropbox, Dropbox only syncs once the script completes (say, if I give it a Keyboard interrupt). I've found that I can get Dropbox to sync if I run touch does_it_update_dropbox.h5 on a Unix machine. However, my machine at my lab is a Windows.

Stack Overflow, how can I get an HDF5 file to sync over Dropbox as it's being written inside of a Windows computer?

Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29
  • 1
    If all you need is "touch" for windows, take a look at this https://stackoverflow.com/questions/30011267/windows-equivalent-of-touch-i-e-the-node-js-way-to-create-an-index-html or write a small python script like `open("does_it_update_dropbox.h5", "ab").write("")` – Pablo Jun 22 '17 at 19:15

1 Answers1

0

Pablo's answer is correct, and led me to a more elegant solution.

import os
filename = "does_it_update_dropbox.h5"
h5file.flush()
os.stat(filename) # this does the magic of updating the filesize on the disk
Jonathan Wheeler
  • 2,539
  • 1
  • 19
  • 29