title: How to read a text file in Python that is never saved
body: <p>I have a log file containing data that I need to read in real-time to check when certain events have occurred. The way the log files work is that there is one &quot;live&quot; log (the one I need to monitor) and many archived logs. When the &quot;live&quot; log gets to a certain size it is then saved as an archived log. With my current code I am able to monitor a local text file for changes being written to it:</p>
  <pre><code>    import time
  
  def follow(thefile):
      thefile.seek(0, 2)
      while True:
          line = thefile.readline()
          if not line:
              time.sleep(0.1)
              continue
          yield line
  
  
  if __name__ == '__main__':
      logfile = open(&quot;folder1\\folder2\\.txt&quot;, &quot;r&quot;)
      loglines = follow(logfile)
      for line in loglines:
          print(&quot;&gt;&gt;&gt; &quot; + line)
  
  </code></pre>
  <p>However the key issue is that this only picks up that data has been written to the file after I have saved the changes. In the file I need to monitor a save never occurs until it reaches a certain size. This is what is currently preventing me from reading any of the data being written to it in real-time, it instead all comes through at once when it is saved as an archived log.</p>
  <p>My question is this, is there any way possible to read the data being written to it when the file is not being actively saved?</p>