readline() after popen hangs

Peter Hansen peter at
Wed Nov 12 16:21:51 CET 2003

Thomas Steffen wrote:
> here my code:
> ...
> (sin, souterr) = os.popen4(command)
> while 1:
>   line = souterr.readline()
>   print line
>   if not line:
>       break
> ...
> Now I have the problem: the last two lines are written after five
> (5!!!) minutes. Why so a long time?

Note that doing "print line" before the check for "not line" doesn't
make sense, as you would then be printing an empty line when in fact
you had reached the end of the data.

You don't show the command involved, so we're just guessing.  My
guess is that you are not providing the other program that you 
are invoking with the input data that it needs, via sin, and
that after the five minute timeout the program is quitting and
you are getting the final output only as it exits.

Why are you grabbing "sin" if you aren't going to use it?


More information about the Python-list mailing list