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

45 views
Skip to first unread message

Manu

unread,
Oct 18, 2011, 9:26:52 AM10/18/11
to cherrypy-devel
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
Reply all
Reply to author
Forward
0 new messages