Does python's sys.stdin.read() block?

I'm adapting this Django management command for my own purposes. The script is a simple while-loop daemon that reads from sys.stdin (line 152, in command.handle()) according to a protocol and writes results to sys.stdout.

I would expect sys.stdin.read() to block until it receives something, but I find that when I run this script, it eats up 100% CPU before any data has been sent or received.

  1. Does sys.stdin.read(n) block?
  2. If not, how can I make this daemon more polite?
  3. Is time.sleep(s) safe to use, or will I miss input or be slow to respond?

6
задан David Eyk 7 December 2010 в 20:22
поделиться