Alright, here we go. The attached program exhibits the problem for me on MySQLdb 
0.9.2, but not 0.9.1. Admittedly, other variables changed too.

Can a couple more people try it and report their results? A Linux build of 0.9.3 beta 
would be especially interesting.

Once I collect a few more data points, then I'll send this on to Andy Dustman and see 
what he says...

-Chuck
--
http://ChuckEsterbrook.com/
"""
This program will do this 1,000 times:
        select * from TABLE limit 1
--making a new connection each time.

Generally this succeeds in MySQLdb 0.9.1 and earlier,
and fails in 0.9.2--regardless of anything else.

To run:
        Edit the config class below with your db info.
        Then run.

Success:

        Python 2.1.1
        MySQLdb 0.9.1
        MySQL 3.23.41
        Mandrake ?7.x?
        Chuck Esterbrook on 2003-07-11

        Python 2.1.2
        MySQLdb 0.9.1
        MySQL 3.23.36
        RedHat ?7.x?
        Chuck Esterbrook on 2003-07-11

Failures:

        Python 2.3.2
        MySQLdb 0.9.2
        MySQL 3.23.41
        Windows XP Pro SP1
        Chuck Esterbrook on 2003-07-11
100
101
Traceback (most recent call last):
  File "\\192.168.1.50\echuck\mysql-prob.py", line 57, in ?
    fetch()
  File "\\192.168.1.50\echuck\mysql-prob.py", line 44, in fetch
    passwd=config.password)
  File "C:\Python23\Lib\site-packages\MySQLdb\__init__.py", line 63, in Connect
    return apply(Connection, args, kwargs)
  File "C:\Python23\Lib\site-packages\MySQLdb\connections.py", line 115, in __init__
    self._make_connection(args, kwargs2)
  File "C:\Python23\Lib\site-packages\MySQLdb\connections.py", line 41, in 
_make_connection
    apply(super(ConnectionBase, self).__init__, args, kwargs)
_mysql_exceptions.OperationalError: (1040, 'Too many connections')
"""

import MySQLdb


class config:
        db       = ''
        user     = ''
        password = ''
        table    = ''
        repeatPerTable = 1000

def fetch():
        for i in range(config.repeatPerTable):
                print i
                conn = MySQLdb.connect(db=config.db, user=config.user,
                                                                passwd=config.password)
                cur = conn.cursor()
                cur.execute('select * from %s limit 1' % config.table)
                results = cur.fetchall()

                # The following are feeble attempts to fix the problems
                # experienced with MySQLdb 0.9.2. They didn't help.
                #import gc, time
                #gc.collect()
                #time.sleep(0.1)  # give some time for sockets to close?
        print 'success!'


if __name__=='__main__':
        fetch()

Reply via email to