0

I'm a bit new to Python and I'm having trouble understanding some code from this answer:

https://stackoverflow.com/a/3753314/52551

The code is:

@cherrypy.expose
def update(self):
    cl = cherrypy.request.headers['Content-Length']
    rawbody = cherrypy.request.body.read(int(cl))
    body = simplejson.loads(rawbody)
    # do_something_with(body)
    return "Updated %r." % (body,)

Like I said I'm a bit new at Python so my confusion is how cherrypy.request is able to provide the appropriate request context. If two clients make a request couldn't the first client's request information be overwritten by the second client's request information if there is a context switch somewhere inside the update method?

Community
  • 1
  • 1
Spencer Ruport
  • 34,865
  • 12
  • 85
  • 147

1 Answers1

2

CherryPy uses a threading.local object to manage the request and response context.

A. Coady
  • 54,452
  • 8
  • 34
  • 40