From: Chuck E. <ec...@mi...> - 2000-12-05 16:25:30
|
Excellent point. At 10:58 AM 12/5/2000 -0500, Geoff Talvola wrote: >Chuck Esterbrook wrote: > > > You could do that. For example, if you have a common super class for your > > pages called SitePage, it could do something like: > > > > class SitePage(Page): > > > > def __init__(self): > > Page.__init__(self) > > self._dbPool = None > > > > def dbPool(self): > > ''' Returns a single, global instance of a database connection > > pool (as defined in MiscUtils.DBPool). ''' > > if self._dbPool is None: > > from MiscUtils import DBPool > > if not hasattr(DBPool, 'Pool'): > > DBPool.Pool = DBPool.DBPool(args) > > self._dbPool = DBPool.Pool > > return self._dbPool > > > > Now all your pages can say "self.dbPool()". > > Or you could copy DBPool.py to WebKit/Cans. > > Or you could implement Can registration before I do. > > > > -Chuck > >I would wrap the DBPool initialization code with a lock so that two threads >don't try to create the DBPool at the same time. How about: > > >_lock = threading.Lock() > >... > > def dbPool(self): > ''' Returns a single, global instance of a database connection pool >(as defined in MiscUtils.DBPool). ''' > if self._dbPool is None: > _lock.acquire() > try: > if self._dbPool is None: > from MiscUtils import DBPool > if not hasattr(DBPool, 'Pool'): > DBPool.Pool = DBPool.DBPool(args) > self._dbPool = DBPool.Pool > finally: > _lock.release() > return self._dbPool > >-- > > >- Geoff Talvola > Parlance Corporation > gtalvola@NameConnector.com > >_______________________________________________ >Webware-discuss mailing list >Web...@li... >http://lists.sourceforge.net/mailman/listinfo/webware-discuss |