<br><br><div class="gmail_quote">On Mon, Jan 10, 2011 at 9:26 AM, Kushal Kumaran <span dir="ltr"><<a href="mailto:kushal.kumaran%2Bpython@gmail.com">kushal.kumaran+python@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Mon, Jan 10, 2011 at 1:15 PM, Thibaud Roussillat<br>
<div class="im"><<a href="mailto:thibaud.roussillat@gmail.com">thibaud.roussillat@gmail.com</a>> wrote:<br>
> On Sat, Jan 8, 2011 at 3:19 AM, Kushal Kumaran<br>
> <<a href="mailto:kushal.kumaran%2Bpython@gmail.com">kushal.kumaran+python@gmail.com</a>> wrote:<br>
>><br>
>> On Fri, Jan 7, 2011 at 8:08 PM, Thibaud Roussillat<br>
>> <<a href="mailto:thibaud.roussillat@gmail.com">thibaud.roussillat@gmail.com</a>> wrote:<br>
>> > Hi,<br>
>> ><br>
>> > I work with Python 2.4 and CGI.<br>
>> ><br>
>> > I have a CGI which call a Python script in background process and return<br>
>> > result before background task is finished.<br>
>> ><br>
>> > Actually, the browser displays response but it is waiting for end of<br>
>> > background task because the socket is not closed.<br>
>> ><br>
>> > Internet told me that I must close the stdout file descriptor<br>
>> > (sys.stdout.close()) to close the socket but it doesn't work.<br>
>> ><br>
>> > The background task is launched via subprocess.Popen and is attached to<br>
>> > the<br>
>> > root process on ps command.<br>
>> ><br>
>><br>
>> This means that the parent process finished before the child. Call<br>
>> wait() on the Popen object to wait for the child to terminate.<br>
>> Depending on how you create the Popen object, the child process may<br>
>> inherit your own stdout. In that case, the child process may be<br>
>> keeping the socket open after the parent dies.<br>
>><br>
><br>
</div>> <top-posting corrected><br>
<div class="im">><br>
> In fact, the parent process finished before the child, it's why I want to<br>
> run the child in a forked process, and close the socket of the parent task.<br>
><br>
> The goal is not to wait for the child process but to leave it lead one's own<br>
> life as a background task. The client don't have to wait for the end of the<br>
> child process.<br>
><br>
> Is there a way to not inherit from the parent stdout on the child process ?<br>
><br>
<br>
</div>open os.devnull and pass that file object as stdin, stdout and stderr<br>
for the child process. Hopefully the program you are running has been<br>
designed not to expect to be able to use stdin/stdout/stderr.<br>
<br>
Please keep the discussion on the mailing list. Other people on the<br>
list are smarter than me. Also, the convention on this mailing list<br>
is to keep replies below the quoted content.<br>
<br>
--<br>
regards,<br>
<font color="#888888">kushal<br>
</font></blockquote></div><br>Thanks a lot, this works well with a file object opened on /dev/null (or os.devnull) and passed as stdin, stdout and stderr.<br><br>Sorry for the reply, I just do "reply" on my webmail ;)<br>
<br>Regards,<br><br>Thib<br clear="all"><br>