Reputation: 1057
I'm writing to a file for another program (gnuplot) to use as input.
g = open('test.gnuplot', 'w')
g.write("[snip]")
g.close()
os.system("sleep 1")
os.system("gnuplot test.gnuplot")
If I omit the sleep 1
gnuplot generates a mangled file - seemingly because the file I just wrote isn't "ready" yet (if I'm wrong please tell me what the real reason is).
I'm guessing there is a more elegant way to wait for the file to be ready for reading, what is it?
Upvotes: 1
Views: 269
Reputation: 3702
Try this:
g = open('test.gnuplot', 'w')
g.write("[snip]")
g.flush()
os.fsync(g.fileno())
os.system("gnuplot test.gnuplot")
And take away the os.system("sleep 1")
. I think the buffer is not yet written to the file. See the python fsync docs.
Upvotes: 1