Re: subprocess & redirect
Philip Semanchuk <[email protected]>
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
On Mar 22, 2006, at 6:45 PM, Philip Semanchuk wrote:
> On Mar 21, 2006, at 4:45 PM, Jonathan Ellis wrote:
>
>> Strange. My first guess would be that the child process is somehow
>> interacting with stdout (which Spyce redirects to an internal file
>> handle) which screws things up here. But even when I specify
>> subprocess.PIPE for the subprocess stdin/out/err I get the same
>> results.
>> So I don't know. Let me know if you figure it out. :)
Jonathan,
You were correct, although it wasn't stdout that was the problem (even
though that makes the most sense). If I supply the parameter
"close_fds=True" to subprocess.Popen(), the problem goes away. The
documentation says, "If close_fds is true, all file descriptors except
0, 1 and 2 will be closed before the child process is executed." So it
sounds like the child process was holding open some file and Spyce's
processing couldn't complete until the child exited and the file was
closed.
Oddly enough, redirecting the stdin/stdout/stderr of the child process
doesn't seem to make a difference.
Anyway, just for clarity here's the working code:
[[\
import subprocess
import time
TheLongRunningProcess = "/usr/local/MyStuff/src/foo.py"
subprocess.Popen(["python", TheLongRunningProcess], close_fds=True)
response.write("<p>Spawn complete at %s</p>\n" %
time.strftime("%M:%S", time.gmtime()))
]]
Bye all
Philip
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642