Understanding global object persistence in Python WSGI apps

前端 未结 3 772
庸人自扰
庸人自扰 2021-02-05 20:01

Consider the following code in my WebApp2 application in Google App Engine:

count = 0

class MyHandler(webapp2.RequestHandler):

    def get(self):

        glob         


        
3条回答
  •  清酒与你
    2021-02-05 20:53

    In the case of your first question I think you might consider the webapp2.Request.registry feature. It's a dict to store instances that diferent modules can share during the lifetime of the request.

    On the other hand it is also useful the webapp2.WSGIApplication.registry. In this case the instances persist between requests and can be shared (and reused) for whatever your app need during the lifetime of your application, avoiding creating instances on the global scope.

提交回复
热议问题