views:

215

answers:

3

i'm using Python with MySQL and Django. I keep seeing this error and I can't figure out where the exception is being thrown:

Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in > ignored

I have many "try" and "exception" blocks in my code--if the exception occurred within one of those, then I would see my own debugging messages. The above Exception is obviously being caught somewhere since my program does not abort when the Exception is thrown.

I'm very puzzled, can someone help me out?

+1  A: 

This is a Python Error.

See: http://eric.lubow.org/2009/python/pythons-mysqldb-2014-error-commands-out-of-sync/

It looks like there is a problem with your MySQLdb Query.

Todd Moses
thanks for the link. I don't use any explicit MySQL queries or use any cursor objects. All the queries I do go through Django objects. One big problem for me is not being able to see where this exception is being thrown.
Shlomo Shmai
A: 

I believe this error can occur if you are using the same connection/cursor from multiple threads. However, I dont think the creators of Django has made such a mistake, but if you are doing something by yourself it can easily happen.

truppo
I have no multithreading in my program, also only one instance of my program is running. I should be the only one accessing the database when my program is running. Are there any debugging techniques to see where the exception is thrown? I have my program set to run over a large set data. If I only test a small subset of data, everything is ok. But when I set it off to run on the entire set, this MySQL exception appears... Right now, I'm running the whole set and piping both standard in and standard error to see if I can get a better idea of where the problem is showing up.
Shlomo Shmai
A: 

After printing out a bunch of stuff and debugging, I figured out the problem I think. One of the libraries that I used didn't close the connection or the cursor. But this problem only shows up if I iterate through a large amount of data. The problem is also very intermittent and I still don't know who's throwing the "command out of sync" exception. But now that we closed both the connection and cursor, I don't see the errors anymore.

Shlomo Shmai