I need to access a global variable that maintains its state compared to other servers.
In this example, the global variable r , and it increases with each request.
How can I make r global in cherrypy?
import cherrypy import urllib class Root(object): @cherrypy.expose def index(self, **params): jsondict = [('foo', '1'), ('fo', '2')] p = urllib.urlencode(jsondict) if r!=1 r=r+1 raise cherrypy.HTTPRedirect("/index?" + p) return "hi" cherrypy.config.update({ 'server.socketPort': 8080 }) cherrypy.quickstart(Root()) if __name__ == '__main__': r=1
source share