Reference: http://blog.sina.com.cn/s/blog_73951d180101eck0.html
The webpy is easy to use and very lightweight. In particular, its operational database is very convenient.
Import webdb = Web.database (Dbn=dbn,host=host,db=database,user=user,pw=password, charset=charset) data = Db.select ([' I_project '], what= ' P_class ', where= ' p_id = $PlatformBatchID ', limit= ' 1 ', Vars=locals ())
But instead of actively releasing the connection, the number of connections will increase over time.
Monitor MySQL connection count
Show full processlist; Show status like '%conn% ';
Workaround
1) Install Dbutils
1.0) Installation
Pip Install Dbutils
1.2) use
db = Web.database (Maxshared=5,mincached=1,maxcached=5,maxconnections=10,dbn=dbn,host=host,db=database,user=user, Pw=password, Charset=charset)
* mincached: Number of empty connections opened at startup (default 0 means no connection is created at start)
* Maxcached: The maximum number of connections used by the connection pool (the default value of 0 means unlimited connection pool size)
* Maxshared: The maximum number of shared connections allowed (the default value of 0 means that all connections are private) if the maximum number is reached, the connection requested for the share will be used for sharing.
* MaxConnections: Maximum allowable number of connections (default 0 means no limit)
2) Active release of connections and cursor
Finally: #close cursor self.db._db_cursor (). Close () #close connection self.db._db_cursor (). Con Nection.close ()
web.py releasing the database connection