it looks good.... just wondering if that would work with fastcgi ? say that we have 10 fastcgi running... are they sharing the modules ?
On Tue, Feb 7, 2012 at 10:53 PM, Ross Peoples <[email protected]>wrote: > Sorry Mariano, I misspelled your name in my last post :) > > To give you a better example of what you might want to do here is a more > advanced module that makes a static class and better resembles the > singleton pattern: > > class Counter(object): > instance = None > > @classmethod > def get(cls): > if cls.instance == None: > cls.instance = Counter() > > return cls.instance > > def __init__(self, message='Hello World!'): > self.message = message > self.count = 0 > > def get_count(self): > self.count += 1 > return self.count > > def get_message(self): > return self.message > > > Then your controller would look something like this now: > > from mymodule import Counter > counter = Counter.get() > count = counter.get_count() > > return dict(count=count) > > By calling Counter.get() instead of Counter(), we ensure that there is > only ever once instance of the Counter object, and that the object will > last for the lifetime of the web2py instance. > -- Sebastian E. Ovide

