On Mar 3, 5:08 pm, Graham Dumpleton <[email protected]>
wrote:
> Okay, that one specific case will cause sys.path to grow.
>
> What happens is that on very first load of WSGI script file, if it
> fails at global level it will log error and then throw what was loaded
> away and so will look as if never loaded. If the script isn't fixed
> then every subsequent request will do the same thing and because
> adding to sys.path is cumulative and before where the error is, it
> will keep growing.
>
> It is hard to protect against that case in mod_wsgi. I should document
> this specific case as a sub not in that reloading source code
> document.
>

Interesting. Are you sure that protecting against doing cumulative
actions at global scope in the wsgi file is enough? If you do an
import, for example, seems like it could do fairly arbitrary things at
global scope, which one might not know about.

What led to my finding this was an inability to import
django.core.handlers.wsgi, which prompted me to start watching
sys.path. I still don't understand why I wasn't able to import. The
correct path was in sys.path (multiple times), but the wsgi script
consistently failed with an exception saying there was no such module
(which I could only discover by trapping the exception during the
import and dumping it to a file). I suspect now that previous failures
had mucked up something else in the global context. It seemed to be
persistent across "reloads" of the wsgi script: that is, editing the
file, which should have caused a reload, didn't clear the issue.
Restarting apache did clear it.

If errors at this level are hard to catch from mod_wsgi, could they be
caught in the script itself? E.g. could you put the whole script in a
"try" block, and on exception do something to cause wsgi to ditch the
global context and restart?

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to