Massive unit test vs MySQL

Richard Wesley hawkfish at
Tue Sep 9 00:30:45 CEST 2003

In article <mailman.1062774119.18681.python-list at>,
 Andy Todd <andy47 at> wrote:

> Richard Wesley wrote:
> > I don't know if this is really a Python question of a MySQL question, 
> > but i am hopen that there is enough overlap that someone can help me ;-)
> > 
> > I have a unit test suite for our server that loads a clean database 
> > image for many of the tests.  I use
> > 
> > p = os.popen('mysql -u uid -ppassword mydatabase', 'w')
> > p.write(sql_commands)
> > 
> > to load the database.
> > 
> > While the tests are running, I find that mysql has a growing number of 
> > "Sleeping" threads in the 'show processlist' table.  Towards the end of 
> > the test suite, the database loads start to fail with a MySQL error of 
> > "ERROR 1040: Too many connections".
> > 
> > So my question would be, is there any way to shut down the child process 
> > so that MySQL notices and cleans up after itself before it runs out of 
> > threads?
> > 
> > TIA,
> > 
> As you aren't using the Python MySQL module and just piping commands to 
> an OS process then its likely to be a MySQL problem.
> However, its hard to figure out what you're doing wrong because you 
> don't tell us what you are doing. What, for instance, are the contents 
> of 'sql_commands'?

They are the output of a mysqldump command that was read in from a file.

> Generally, if a database complains about too many connections it is 
> because you are explicitly (and repeatedly) connecting to it and then 
> not releasing those connections when you are finished with them.

Yes, that is the problem, but it is not clear how to release the 
connections.  They get released immediately when the script terminates.  
I am wondering of it is a gc problem.

> Then again, if you are just loading test data into a clean database I'd 
> suggest using some of the MySQL utilities to back up and restore and not 
> writing your own code. Have a look at mysqldump 
> (

That is what I am doing.


- rmgw


Richard Wesley                                  Trusted Media Networks, Inc.

"You miss too much these days if you stop to think."
                  - U2, "Waiting for the End of the World"

More information about the Python-list mailing list