title: Taking input from sys.stdin, non-blocking
body: <p>I'm working on a bot for a competition that receives its input through <code>sys.stdin</code> and uses Python's <code>print()</code> for output. I have the following:</p>
  
  <pre><code>import sys
  
  def main():
      while True:
          line = sys.stdin.readline()
          parts = line.split()
          if len(parts) &gt; 0:
              # do stuff
  </code></pre>
  
  <p>The problem is that the input comes in through a stream and using the above, blocks me from printing anything back until the stream is closed. What can I do to make this work?</p>