Skip to content

Commit 65603dd

Browse files
author
Greg Bowler
authored
Flush file contents each time
1 parent d66cbf9 commit 65603dd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

data-log.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import sys
44
import subprocess
5+
import os
56

67
start = str(time.time())
78
fpath = "/home/logbox/serial/"
@@ -55,18 +56,24 @@
5556

5657
if(data.startswith("C1")):
5758
c1 = data.split("\t", 1)[1]
58-
c1file = open("/home/logbox/c1", "w")
59+
c1file = open("/home/logbox/c1", "w", 1)
5960
c1file.write(c1)
61+
c1file.flush()
62+
os.fsync(c1file)
6063
c1file.close()
6164
if(data.startswith("C2")):
6265
c2 = data.split("\t", 1)[1]
63-
c2file = open("/home/logbox/c2", "w")
66+
c2file = open("/home/logbox/c2", "w", 1)
6467
c2file.write(c2)
68+
c2file.flush()
69+
os.fsync(c2file)
6570
c2file.close()
6671
if(data.startswith("C3")):
6772
c3 = data.split("\t", 1)[1]
68-
c3file = open("/home/logbox/c3", "w")
73+
c3file = open("/home/logbox/c3", "w", 1)
6974
c3file.write(c3)
75+
c3file.flush()
76+
os.fsync(c3file)
7077
c3file.close()
7178

7279
sys.stdout.write(data)

0 commit comments

Comments
 (0)