> Based on my experiments, it does seem like each Apache process
> maintains a live Django object which it reuses request after request
> and which maintains state such as global variables in modules between
> requests. Does that mean that a Django instance has some kind of loop
> in it that waits for requests and then creates responses?

The wait loop is inside Apache - Django just exports a funtion which
Apache calls for every request, e.g. the "handler" function in
core/handlers/modpython.py

> The slave script that gets called with subprocess.Popen uses
> fcntl.flock to lock onto an arbitrary file while it's working. A
> middleware looks for tasks that need to be completed on every response
> and if work needs to be done, quickly tries to get a lock on the lock
> file in a non-blocking way, and if it can, it releases the lock and
> uses Popen to start the slave. Since the task files are numbered, they
> form a sort of queue. The point of all this is to generate thumbnails
> and not wait around for it.

You might get some mileage out of the multiprocessing module, which has
proper lock and queue objects.  Although not available natively in
python 2.5, it can be installed as a stand-alone package.

This way you could spawn a single worker process (or pool of processes)
for each django instance, and have your middleware simply push tasks
onto a queue for them to handle.  It also lets you specify your worker
processes as "daemonic" so they're cleaned up automatically when Django
exits.


  Cheers,

     Ryan

-- 
Ryan Kelly
http://www.rfk.id.au  |  This message is digitally signed. Please visit
r...@rfk.id.au        |  http://www.rfk.id.au/ramblings/gpg/ for details

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to