On 4 March 2011 08:33, bc <[email protected]> wrote:
> I read over the docs for wsgi with virtualenv, and am now calling
> site.addsitedir() on the site-packages of my virtual install, from the
> wsgi script. However I was getting errors trying to import a module
> (django.core.handlers.wsgi). Doing the addsitedir() and import on the
> command line worked fine.
>
> While trying to debug this, I noted that if I logged sys.path in the
> wsgi file, it grows every time I try to load a page, so eventually the
> site path, and eggs for pip, etc., are in the path many times.
>
> I don't understand why the wsgi script is being invoked on every page
> load. It's not the application function that is invoked. It's the
> whole file. It's like the file is reloaded with every page load. And
> the sys.path is persistent, for some reason, so it grows every time.
>
> The script looks something like
>
> f=open('tmp/log', 'a')
> sitedir='/path/to/python/virtual/environment'
> print >> f, sys.path
> site.addsitedir(sitedir)
> print >> f, sys.path
>
> def application(environ, start_response)
> ...
> ...
>
>
>
> I'm wondering if this happens because of a python error later while
> processing the request. For example, maybe a later error invalidates
> the subinterpreter, so on the next request a new subinterpreter is
> created. But the sys.path is somehow retained, and so when the new
> subinterpreter starts up, the path gets extended?? I'm wildly
> guessing, at this point.

Don't use embedded mode. Preferably use daemon mode and you will not
have this problem. This is because in daemon mode the whole process is
reloaded when WSGI script file is changed whereas in embedded mode,
just the WSGI script file is reloaded when it is changed.

Read:

  
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Embedded_Mode

Graham

-- 
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