Menu

Not letting go

Help
2005-05-25
2012-09-19
  • Dagur Páll Ammendrup

    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?

     
    • Andy Dustman

      Andy Dustman - 2005-05-25

      What version of MySQLdb?

       
      • Dagur Páll Ammendrup

        1.2.1 "gamma" 1

         
    • Andy Dustman

      Andy Dustman - 2005-05-26

      What happens when you put your code in a loop?

       
      • Dagur Páll Ammendrup

        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

         
        • estrand

          estrand - 2005-05-26

          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

           
          • Dagur Páll Ammendrup

            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.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.