Hi,

Couple of suggestions.

Subclass Threading.local to get safe per thread storage ( db connections
etc).

class AppClass(threading.local):
  ReadonlyWhatever = 10
  def __init__(self):
    self.DB = ...  #called once per thread
App = AppClass

Now import App everywhere and you have a safe place for thread local and
shared data.  Plus you can use locks for cross thread data but again see
below...

Use redis for cross process and cross request storage of in memory data.
This works great and is high speed and you do not limit yourself to 1
process that is likely to die anytime you restart apache or touch a wsgi
file.

Thanks!
On Jun 16, 2014 5:58 PM, <[email protected]> wrote:

> Hello.
>
> I am trying to share data in memory between invocations of my request
> handler.
> I assume that a module gets imported only once per lifetime of the
> application and mod_wsgi does not re-import the module for next request.
>
> So basically, I am writing something like this:
>
> class X:
>    ...
>
> XX = X()
>
> def application(environ, start_response):
>     ...
>     XX.method()
>     ...
>
> and my assumption is that XX and its attributes survive unchanged between
> requests.
>
> I have threads=1 and omit "processes" argument, which is equivalent to
> processes=1
>
> I found that this is not always true. What I am seeing is that the module
> gets re-imported pretty consistently if I access my server from some other
> client.
>
> In other words, as long as I access my server from the same browser or
> repeat the same wget command from the same computer, I reach the same XX
> object. But if I switch to certain other way to access the page, I see that
> the module is re-imported and the object is re-created.
>
> Can someone explain this please ?
>
> Thanks.
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/modwsgi.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to