Hello Anand, >> I find that code.py is imported multiple times upon start. >> I wonder what is the best way to instantiate single objects >> in a web.py application, for example, a logger. >> >> I also notice that for one request, the handler functions >> are called multiple times. Not sure if it's because >> I'm using reloader.
> Yes, it is because of using reloader. Since it is not possible to > reload __main__ module, web.py imports that module another time with > its name. So you must have seen that the main is imported twice. If > you find it importing more than twice, then probably it is a problem. > What is the version of web.py you are using? I see. I'm using 0.22. Indeed, it's imported twice when reloader is used, only once when reloader is not used. Because of this, I haven't figured out a way to properly instantiate a single object when reloader is used. I tried the singleton code below. It works fine in other projects as a singleton (the '__init__' line prints once) but it doesn't work properly in web.py. I see two lines of '__init__' printed out. # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52558 class _Singleton(object): def __init__(self): # just for the sake of information self.instance = "Instance at %d" % self.__hash__() print '__init__' _singleton = _Singleton() def Singleton(): return _singleton A separate question (also in my original email but Anand didn't provide an answer for), I wonder why I'm seeing the url handler function called multiple times in my log for one single request, I mean, for example, the GET function in class hello in the web.py sample. Jack --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web.py" 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/webpy?hl=en -~----------~----~----~----~------~----~------~--~---
