On Feb 14, 11:30 am, Eric Ka Ka Ng <[email protected]> wrote:
>
> however, in my case, I have a variable defined inside a module that
> would be imported (and cached) , but i would like to have that
> variable be re-initialized in every requests. In particular, with this
> example
>
> ### mymodule.py
> counter = 0
> def increment():
> global counter
> counter += 1
> return counter
>
> ### myhandler.py
> import mymodule
>
> print "Content-Type: text/plain"
> print ""
> print "My number: " + str(mymodule.increment())
> print "My number: " + str(mymodule.increment())
>
> I would like to "disable" the caching and to have
> "counter" being re-initialized to 0 in every request.
>
> Any way to achieve this?
### mymodule.py
counter = 0
def increment():
global counter
counter += 1
return counter
de reset():
global counter
counter = 0
### myhandler.py
import mymodule
def main():
mymodule.reset()
respond()
def respond():
print "Content-Type: text/plain"
print ""
print "My number: " + str(mymodule.increment())
print "My number: " + str(mymodule.increment())
if __name__ == '__main__':
main()
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.