great thx to Darren and Stephen! Stephen's solution is very simple and easy, and it works for me. I believe Darren's one works too but finally i choose Stephen's one as this gives finer control and I can adjust when to retain the counter value, when to reset, without scarifying the performance while the module can still be cached. thx again to all of you
- eric On 15 February 2010 00:49, Stephen <sdea...@gmail.com> wrote: > > > On Feb 14, 11:30 am, Eric Ka Ka Ng <ngk...@gmail.com> 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 google-appeng...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/google-appengine?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to google-appeng...@googlegroups.com. To unsubscribe from this group, send email to google-appengine+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.