title: Avoiding Python globals in Google App/Cloud Engine
body: <p>There must be a better and more Pythonic way to do this. I have created a small GAE app that demonstrates my problem (and ignorance). Here you enter your name on an entry page. The app then greets you and increments a number with every click. Works great -- until someone else uses the app at the same time, at which point one user inherits the other's name. </p>
  
  <p>Is this because the name is stored in <code>a_state</code>, a global (singleton) object declared at the bottom? If so, how can I make sure all users keep their own names? Thanks in advance!</p>
  
  <pre><code>import webapp2
  
  class AState:
      my_name = "Foo"
      a_number = 42
  
  class GetName(webapp2.RequestHandler):
      def post(self):
          the_state.my_name = self.request.get('the_name')
          self.redirect('/main')
  
      def get(self):
          self.response.write("""
          &lt;html&gt;&lt;body&gt;&lt;form action="/" method="post"&gt;
              Type your name &lt;input type="text" name="the_name"&gt;
              &lt;input type="submit" value="Continue"&gt;
          &lt;/form&gt;&lt;/body&gt;&lt;/html&gt;
          """)
  
  
  class Main(webapp2.RequestHandler):
      def get(self):
          the_state.a_number += 1
          self.response.write("""
          &lt;html&gt;&lt;body&gt;&lt;form action="/main" method="get"&gt;
          Hello, %s! The number is %d. 
          &lt;input type="submit" value="Keep going"&gt;
          &lt;/form&gt;&lt;/body&gt;&lt;/html&gt;
          """ % (the_state.my_name, the_state.a_number))
  
  
  app = webapp2.WSGIApplication([
      ('/', GetName),
      ('/main', Main)
  ], debug=True)
  
  the_state = AState()
  </code></pre>
  
  <p>Note: In the real app, I'm using <code>ndb</code> to store (successfully!) information that should be shared among all users. My problem is with this more ephemeral, user-specific info.</p>
  
  <p>So is the right solution to bite the bullet and store even this stuff in the datastore?</p>