I have this simple script:
import MySQLdb
db = MySQLdb.connect(db='test', user="user", passwd="passwd")
cur = db.cursor() cur.execute("SHOW STATUS LIKE 'connections';") print "%s Connections" % (cur.fetchone()[1]) cur.close() db.commit() db.close()
Each time I run it the number of connections increases. Shouldn't python let go of the connection when the script stops running?
What version of MySQLdb?
1.2.1 "gamma" 1
What happens when you put your code in a loop?
I did 10 loops and got this:
150 Connections 151 Connections 152 Connections 153 Connections 154 Connections 155 Connections 156 Connections 157 Connections 158 Connections 159 Connections
Hi,
The status variable "CONNECTIONS" is the total number of connection attempts since the server started, not the number of current connections. So it's expected that the count would continue to grow. See:
http://dev.mysql.com/doc/mysql/en/server-status-variables.html
--Eric
I wish I knew that a few weeks ago.
Don't believe everything you read on the the internet :-(
Log in to post a comment.
I have this simple script:
!/usr/bin/env python
import MySQLdb
db = MySQLdb.connect(db='test', user="user", passwd="passwd")
cur = db.cursor()
cur.execute("SHOW STATUS LIKE 'connections';")
print "%s Connections" % (cur.fetchone()[1])
cur.close()
db.commit()
db.close()
Each time I run it the number of connections increases. Shouldn't python let go of the connection when the script stops running?
What version of MySQLdb?
1.2.1 "gamma" 1
What happens when you put your code in a loop?
I did 10 loops and got this:
150 Connections
151 Connections
152 Connections
153 Connections
154 Connections
155 Connections
156 Connections
157 Connections
158 Connections
159 Connections
Hi,
The status variable "CONNECTIONS" is the total number of connection attempts since the server started, not the number of current connections. So it's expected that the count would continue to grow. See:
http://dev.mysql.com/doc/mysql/en/server-status-variables.html
--Eric
I wish I knew that a few weeks ago.
Don't believe everything you read on the the internet :-(