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 way I handled my problem after is I had a directory where the model writes numbered files, each one containing an instruction for the slave. 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. I feel like there much be a better way I could have done this, although I'll say this much for my solution, it works. Of course, I seem to be creating a small army of the undead, but I'll worry abou that later. I guess zombies are not the end of the world, if there's only few of them. Stephen On Sun, Feb 22, 2009 at 10:29 AM, stevedegrace <degr...@gmail.com> wrote: > > I don't think I'm understanding this very well. By doing some > inspection, I see that Apache is running under two PIDs, which makes > sense because ServerLimit right now is set to 2. What I'm wondering > is, does each of those processes have a persistent instance of Django > in its own python process waiting for requests, i.e., if I set a > global variable in a module, do requests that happen to be served by > the same Apache process have that value set persistently from request > to request? > > I want to start a subprocess to handle some intensive work for me > making thumbnails, and I want to understand how Django works better in > order to have a better grasp of what is going on when I do. I don't > want to inadvertently do something to annoy my hosting company - I'm > going to try and write this thing so that only one copy of the slave > process is going at any one time and working away at the tasks one at > a time. I think I'm going to handle that through a lock file in any > case, but it still would really help me if someone could clarify what > happens when a Django 1.0.2 website receives a request, given the > configuration of running behind Apache 2 via mod_wsgi 2.0 with Python > 2.5 (not 2.6, curses... I really had my heart set on trying the > multiprocessing package :)). > > Thanks for any help! > > Stephen > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---