At 01:18 PM 6/11/2001 -0400, Jeff Johnson wrote:
> > Webware.MiscUtils.DBPool
>
>That'll work for me.  This is what I did, let me know if I did it
>wrong:
>
>__init__.py:
>def contextInitialize(app, ctxPath):
>         from MiscUtils.DBPool import DBPool
>         import pgdb
>         app.dbPool = DBPool(pgdb, 10, 'myhost:mydb:myname:mypw')
>
>SitePage.py:
>class SitePage(Page):
>         def db(self):
>                 """
>                         Usage:
>                         ==================================
>                         db = self.db()
>                         c = db.cursor()
>                         c.execute("select * from Book")
>                         rs = c.fetchall()
>                         for r in rs:
>                                 self.writeln(r[0])
>                 """
>                 return 
> self.application().valueForKey('dbPool').getConnection()
>
>
>
>If this is right, should some of it be added to the docstring for
>DBPool?  Currently it tells how to create the dbPool but not how to
>make it persist beyond a single servlet call.

There are a number of different ways to do this, but your solution works 
just fine.  I think it's just a matter of personal preference.

Another approach is to put your initialization code into a regular Python 
module.  Then you just import it and use the variable.  This works because 
modules only get imported once, plus the imports are guaranteed to be 
thread-safe.  For example:

MyDBPool.py:
from MiscUtils.DBPool import DBPool
import pgdb
myDBPool = DBPool(pgdb, 10, 'myhost:mydb:myname:mypw')

SitePage.py:
from MyDBPool import myDBPool
class SitePage(Page):
         def db(self):
                 return myDBPool


_______________________________________________
Webware-devel mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/webware-devel

Reply via email to