2008/10/3 William Dode <[EMAIL PROTECTED]>: > > Hi, > > In daemon mode, with threads=1 : > > def application(environ, start_response): > > status = '200 OK' > output = "con= %s" % cgi.escape(repr(pool.connection())) > loc = threading.local() > try: > loc.i += 1 > except AttributeError: > loc.i = 0 > output = 'i=%s' % loc.i > > response_headers = [('Content-type', 'text/html'), ] > start_response(status, response_headers) > > return [output] > > threading.local doesn't stay between requests. Is it normal ? > > I found this with DBUtils wich doesn't reuse connection. > > I missed something ?
If you want something to persist between requests, just make it a global variable within the file, you do not need to use threading.local(). Depending on type of data, global declaration may be needed in function scope so that on assignment it doesn't just create a local variable to function (which is what is happening now). In doing this, if a multithreaded application you would however need to protect using thread mutex locks any updates to the global data. This is presuming all threads should share the global data. If each thread should have its own, then threading.local() may be okay, but you need to initialise it once outside of the function, actually at global scope, not like what you are doing now. BTW, also be careful of embedded mode as source code reloading could cause issues in that case. See: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode Graham --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to modwsgi@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---