cherrypy.serving.request and cherrypy.serving.response not thread safe by default ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

cherrypy.serving.request and cherrypy.serving.response not thread safe by default ?

Manu-69
Hi,

I am using cherrypy 3.2.0 to dispatch requests to my own WSGI
applications. I am not at all an expert in cherrypy.

in cherrpy/__init__.py :

The threadlocal _Serving object's docstring says that it's a
threadlocal container for request and response. However, on
instantiation of this _Serving object (at serving = _Serving() ),
request and response seem to be set to class variables (e.g. one
request for all instances of the _Serving() object)
It seems that this object is not directly threadsafe, for example :

class T(threading.Thread):
  def run(self):
    print id(cherrypy.serving.request)

for t in xrange(10):
  T().start()

will return always the same id.

What I think is happening is that the first call to load(request,
response) effectively sets self.response and self.request (and not
_Serving.request and _Serving.response) and makes it threadsafe.

I think the code might be clearer and more roboust with :

class _Serving(_local):

  def __init__(self):
    self.request = _Serving.request
    self.response = _Serving.response


What do you think ?


Regards,

Manu

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