Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are CherryPy object attributes persistent between requests?
    text
    copied!<p>I was writing debugging methods for my CherryPy application. The code in question was (very) basically equivalent to this:</p> <pre><code>import cherrypy class Page: def index(self): try: self.body += 'okay' except AttributeError: self.body = 'okay' return self.body index.exposed = True cherrypy.quickstart(Page(), config='root.conf') </code></pre> <p>I was surprised to notice that from request to request, the output of self.body grew. When I visited the page from one client, and then from another concurrently-open client, and then refreshed the browsers for both, the output was an ever-increasing string of "okay"s. In my debugging method, I was also recording user-specific information (i.e. session data) and that, too, showed up in both users' output.</p> <p>I'm assuming that's because the python module is loaded into working memory instead of being re-run for every request.</p> <p>My question is this: How does that work? How is it that self.debug is preserved from request to request, but cherrypy.session and cherrypy.response aren't?</p> <p>And is there any way to set an object attribute that will only be used for the current request? I know I can overwrite self.body per every request, but it seems a little ad-hoc. Is there a standard or built-in way of doing it in CherryPy?</p> <p>(second question moved to <a href="https://stackoverflow.com/questions/3908577/can-i-use-cherrypy-object-attributes-to-cache-the-output-of-a-page">How does CherryPy caching work?</a>)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload