[Tutor] SOLVED: Re: cgi script: how to continue a process in the background and return from cgi script

2006-02-12 Thread Moritz Lennert
On Fri, February 10, 2006 21:03, Hugo González Monteverde wrote:

 So, could some give me a pointer to possible solutions ? Do I have to
 make the last part of my program a seperate program and go through a
 system call ?

 Hi,

 I have had this problem before. The timeout problem with Apache remains
 because STDOUT of both child and the parent are open. Apache keeps
 thinking the CGI is still sending data until the filehandle is closed.

 I have solved it in the pas using this recipe, which is similar to the
 one you used before:

 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731


I got it to work with this recipe, thanks a lot ! (also to Beilin Zhang
who said the same about IO streams)

Moritz

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cgi script: how to continue a process in the background and return from cgi script

2006-02-10 Thread Moritz Lennert
Hello,

I need some pointers in the right direction for the following problem:

I have a cgi script which reads in some form elements, uses them to 
compose an SQL query, sends that query to the postgresql backend, writes 
the results into a temporary file and sends a mail to the user with the 
link to the file.

The main block of the program is very simple

formulaire = cgi.FieldStorage(keep_blank_values=1)
adresse=formulaire[email1].value
if adresse == :
print_error_adresse()
else:
requete=compose_req(formulaire) #function composing the query
print_info_mail(adresse, requete) #function printing a web page 
telling the user that the query is ongoing and that she will be advised 
by email when it is done
results=req(requete, 91) #function launching the query
fname=fichier_resultats(results) #function writing the results to a file
if(fname):
  envoi_res(fname, requete, adresse) #function sending the email to 
the user


The problem I have is that the process obviously remains active 
throughout the entire program, including the query, and that I, 
therefore, sometimes get timeout problems with apache.

So, what I would like to do is to go through all the steps until the 
printing of the web page and then somehow fork the process of querying 
so that the cgi script terminates and the querying, result file writing 
and email sending are done in the background.

I have no experience with either forking or threading, but the way I 
understand them any child processes die when the parent dies.

I have tried the recipe in 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 which is 
supposed to fork a process as daemon, thus decoupling it from the 
calling terminal, but I don't seem to get it to work (I get one defunct 
process and the child process, but the timeout problem remains). I am 
also not sure this is actually what I need (I don't know if what I 
describe above is decoupling from the calling terminal).

So, could some give me a pointer to possible solutions ? Do I have to 
make the last part of my program a seperate program and go through a 
system call ?

Thank you !

Moritz
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor