Message from discussion
Open and Close a database connection in a request
Received: by 10.58.92.9 with SMTP id ci9mr1151014veb.40.1348088072452;
Wed, 19 Sep 2012 13:54:32 -0700 (PDT)
X-BeenThere: webpy@googlegroups.com
Received: by 10.220.154.17 with SMTP id m17ls1298151vcw.1.gmail; Wed, 19 Sep
2012 13:54:30 -0700 (PDT)
Received: by 10.52.28.83 with SMTP id z19mr1034164vdg.20.1348088070950;
Wed, 19 Sep 2012 13:54:30 -0700 (PDT)
Date: Wed, 19 Sep 2012 13:54:30 -0700 (PDT)
From: ProfessionalIT <lsever...@gmail.com>
To: webpy@googlegroups.com
Message-Id: <6ee0121a-bfb5-4538-ad23-3905ab4a90a7@googlegroups.com>
In-Reply-To: <6410cea1-0ca8-4b5f-9886-54d1dbee67e9@googlegroups.com>
References: <6410cea1-0ca8-4b5f-9886-54d1dbee67e9@googlegroups.com>
Subject: Re: Open and Close a database connection in a request
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_194_29644688.1348088070607"
------=_Part_194_29644688.1348088070607
Content-Type: multipart/alternative;
boundary="----=_Part_195_22068000.1348088070608"
------=_Part_195_22068000.1348088070608
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Well,
I'm trying implement this then in my code.py I have this code:
from model import setDB, unsetDB
def db_handler(handler):
setDB()
result=handler()
unsetDB()
return result
webapp = web.application(urls, globals())
webapp.add_processor(db_handler)
im my model.py I have this code:
db = web.database(dbn=DBN, host=HOST, db=DB, user=USER, pw=PWD)
def unsetDB():
print '>>>>>>>>> in the unset <<<<<<<<<<<'
db = None
print str(db)
def setDB():
print '>>>>>>>>> in th SET <<<<<<<<<<<'
unsetDB()
db = web.database(dbn=DBN, host=HOST, db=DB, user=USER, pw=PWD)
print str(db)
but when I look in my system process monitor I still have a opened
connection with database
any idea ?
------=_Part_195_22068000.1348088070608
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Well,<div><br></div><div> I'm trying implement this then in my =
code.py I have this code:</div><div><br></div><div>from model import setDB,=
unsetDB<br></div><div><br></div><div><div>def db_handler(handler):</div><d=
iv> setDB()</div><div> result=3Dhandler()</div><d=
iv> unsetDB()</div><div> return result</div></div=
><div><br></div><div>webapp =3D web.application(urls, globals())<br></div><=
div><div>webapp.add_processor(db_handler)<br></div></div><div><br></div><di=
v><br></div><div>im my model.py I have this code:</div><div><br></div><div>=
<div>db =3D web.database(dbn=3DDBN, host=3DHOST, db=3DDB, user=3DUSER, pw=
=3DPWD)</div><div><br></div><div>def unsetDB():</div><div> pri=
nt '>>>>>>>>> in the unset <<<<<&=
lt;<<<<<'</div><div> db =3D None</div><div>&nbs=
p; print str(db)</div><div><br></div><div>def setDB():</div><div>&nb=
sp; print '>>>>>>>>> in th SET <<&l=
t;<<<<<<<<'</div><div> unsetDB()</div>=
<div> db =3D web.database(dbn=3DDBN, host=3DHOST, db=3DDB, use=
r=3DUSER, pw=3DPWD)</div><div> print str(db)</div></div><div><=
br></div><div>but when I look in my system process monitor I still have a o=
pened connection with database</div><div><br></div><div>any idea ?</div>
------=_Part_195_22068000.1348088070608--
------=_Part_194_29644688.1348088070607--