[mod_python] psp problem

Jim Gallacher jpg at jgassociates.ca
Wed May 24 22:42:14 EDT 2006


yjfuk wrote:
> 
> I tested it when I run psp with no vars,it does not increase.
> how psp do with the vars?

There must be more going on in your code than you have indicated. The 
use of psp should not have any impact on the mysql connection.

Jim

> 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
>>
>>
> 
> 
> 



More information about the Mod_python mailing list