[Pythonmac-SIG] Subprocess module hangs with select

Bob Ippolito bob at redivi.com
Thu Aug 4 03:11:52 CEST 2005


On Aug 3, 2005, at 1:07 PM, Sriram Srinivasan wrote:

> I wonder if anyone has seen this behavior or can explain it to me.
>
> I Popen a process and monitor its stdout using select, as follows.
>
>      process = Popen(args,stdin=PIPE, stdout=PIPE, stderr=PIPE)
>      while True:
>          if not (process.returncode == None):
>              print process.returncode
>              break
>          ready,_, _ = select.select([process.stdout, process.stderr],
> [], [], 5)
>          if ready:
>          for fd in ready:
>              print fd.readline()
>
> Now this works fine, in that it dumps out everything that the program
> can print, but when the exec'd program finishes executing, the select
> () call just hangs. The timeout on the select has no effect.

I'm relatively sure that subprocess module is not suitable for non- 
blocking IO like that...  Check the docs or shoot a message over to  
python-list, I'm sure someone there knows.

-bob



More information about the Pythonmac-SIG mailing list