Running long script in the background

Erik Max Francis max at alcyone.com
Tue Feb 6 14:40:36 EST 2007


wattersmt at gmail.com wrote:

> I tried flushing stdout and the same thing happens.  As soon as the
> os.popen(command) line runs it stops there, the next print statement
> never even runs.
> 
> I've also tried using os.spawnv to make the process run in the
> background but then the ssh command never runs.

Based on what you describe, this isn't a good application for a 
single-transaction CGI exchange.  The timeouts are not happening at the 
level of your CGI script, but rather either at the HTTP server itself or 
at the remote client.  In either case, fixing it as a one-transaction, 
one-script solution is not going to be very feasible.

A more sensible way to do it is to have one logical page (which could be 
the same physical page if you want) which accepts job requests, spawns 
them off in the background, and offers a link to a second logical page 
which sees if the job has completed -- showing the results if it has -- 
or refreshes periodically if it hasn't yet.

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 20 N 121 53 W && AIM, Y!M erikmaxfrancis
   You could have another fate / You could be in another place
    -- Anggun



More information about the Python-list mailing list