title: can not read correctly from STDIN
body: <p>I have a weird problem to read from STDIN in a python script.</p>
  
  <p>Here is my use case. I have rsyslog configured with an output module so rsyslog can pipe log messages to my Python script.</p>
  
  <p>My Python script is really trivial :</p>
  
  <pre><code>#! /usr/bin/env python
  # -*- coding: utf-8 -*-
  import sys
  
  fd = open('/tmp/testrsyslogomoutput.txt', 'a')
  fd.write("Receiving log message : \n%s\n" % ('-'.join(sys.stdin.readlines())))
  fd.close()
  </code></pre>
  
  <p>If I run <code>echo "foo" | mypythonscript.py</code> I can get "foo" in the target file <code>/tmp/testrsyslogomoutput.txt</code>. However when I run it within rsyslog, messages seems to be sent only when I stop/restart rsyslog (I believe some buffer is flushed at some point).</p>
  
  <p>I first thought it was a problem with Rsyslog. So I replaced my python program with a shell one, without changing anything to the rsyslog configuration. The shell script works perfectly with rsyslog and as you can see in the code below, the script is really trivial:</p>
  
  <pre><code>#! /bin/sh
  cat /dev/stdin &gt;&gt; /tmp/testrsyslogomoutput.txt
  </code></pre>
  
  <p>Since my shell script works but my Python one does not, I believe I made a mistake somewhere in my Python code but I can not find where. If you could point me to my mistake(s) that would be great.</p>
  
  <p>Thanks in advance :)</p>