yjfuk
yjfuk at 126.com
Wed May 24 10:35:13 EDT 2006
I tested it when I run psp with no vars,it does not increase. how psp do with the vars? Jim Gallacher 写道: > > yjfuk wrote: >> >> I use mod_python publish as handler,psp as template and MySQLdb to >> connect the mysql .apache is 2.0.58 use perfork MPM >> >> codes below: >> >> from MySQLdb import connect >> from mod_python import psp >> >> def index (req): >> conn=connect(**{'host':'localhost','user':'root','passwd':'','db':'test'}) >> >> req.content_type = "text/html; charset=utf-8" >> psp.PSP(req,'templates/test.html').run({'name':'jack'}) >> conn.close() >> >> when I flush the exlpore, I see the 'show processlist' in the mysql >> shell is ceaselessly increasing ,why? > > Are you raising an exception such that conn.close() does not get a > chance to run? If so, you could either wrap your code in a try/finally > clause (closing the connection within finally), or better yet, > register a cleanup that will always run when apache finishes > processing the request. > > def index(req): > conn=connect(**{'host':'localhost','user':'root', > 'passwd':'','db':'test'}) > req.register_cleanup(close_db_connection, conn) > req.content_type = "text/html; charset=utf-8" > psp.PSP(req,'templates/test.html').run({'name':'jack'}) > > def close_db_connection(db_con): > db_con.close() > > Jim > >
|