title: How can I monitor a screen session with Python?
body: <p>I need to monitor a <code>screen</code> session in real time using a Python script.  It needs to know when the display changes.  I believe this can be described as whenever <code>stdout</code> is flushed, or a character is entered to <code>stdin</code>.  Is there some way to do this; perhaps with pipes?</p>
  
  <p>I have some code found <a href="http://code.activestate.com/recipes/134892/" rel="nofollow">here</a> that gets a character from stdin, and I assume works on a pipe (if I modify the code, or change <code>sys.stdin</code>)?  </p>
  
  <p>Does the <code>flush</code> function of a stream (like <code>stdout</code>) get called in a pipe, or is it just called explicitly?  My understanding is that the display is only updated when <code>stdout</code> is flushed.</p>