Threads CGI & database connections...

Robert Brewer fumanchu at amor.org
Tue Oct 7 16:30:02 EDT 2003


On Tuesday, October 7, 2003, at 10:23 AM, Chris Lyon wrote:
> We run a sound effects library site.
>
> I use a cgi script written in python to copy files from our file
> repository to a publically viewable directory for clients to pick up
> with locations sent to them in E-mails and on a completion web page.
> Unfortunately since some of the files are fairly large (20-30 Mbytes
> is not untypical) it can take a considerable length of time to copy
> the files across.
> So we would like to implement something that would allow us to quickly
> report back that the process has been started and then copy the files
> across whilst a small piece of javascript will refresh the viewing
> page to indicate the progress.
>

Ian Bicking then answered:
> CGI scripts are run in a single process, so threads won't work for
you. 
> The response hasn't ended until the process quits. Which is to say,
> when you first run the CGI script that starts the copying process,
> that CGI script has to terminate before the copying is finished.  


On Windows, if you use, say, mod_python, and reference the same module
on each request, you can keep that module loaded between requests. This
allows you (during the page request process) to start a new thread. That
new thread will continue to run asynchronously, allowing mod_python to
finish the page request and return control to Apache, so it can close
the connection and deliver the page. Incidentally, this also works with
IIS and ASP, calling Python modules.


Robert Brewer
MIS
Amor Ministries





More information about the Python-list mailing list