web.py releasing the database connection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.