Jim Gallacher
jpg at jgassociates.ca
Wed May 24 08:03:23 EDT 2006
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
|