title: Turn of system file read buffering in Python
body: <p>I have my TCP server written on Tornado , Python web-framework, that receives data every 1-10 seconds. Then I need to read my file 'example.txt' on each iteration , where I store data in list format(JSON), merge my data with old data and write to file again.
  There is one problem - after some time (or some times/some amount of data) , file begins caching(or buffering) , so as result I get non-relevant data from file , each time I want to read it. But file still available for writing and Python writes new, but merged with non-relevant data, to file, I can see it from modification time of file. </p>
  
  <p><code>open('example.txt', 'r', 0)</code> - doesn't help<br>
  <code>python -u</code>  - flag doesn't help<br>
  <code>PYTHONUNBUFFERED variable</code> - doesn't help<br>
  <code>file.flush(), os.fsync()</code> - doesn't help  </p>
  
  <p>P.S. Production server is working on CentOs.</p>
  
  <pre><code>def saveToFile(self, data, path):
          if os.path.exists(path) == True:
              with open(path, 'r', 0) as f:
                  old = f.read()
              try:
                  old = json.loads(old)
              except ValueError:
                  old = {}
          else:
              old = {}
  
          data_to_save = dict(old.items() + data.items())
  
  
          with open(path, 'w', 0) as f:
              f.write(json.dumps(data_to_save))</code></pre>
  
  <p>I call this method at each new part of data I get.</p>