Who throws (and catches) this MySQL exception?

I am using Python with MySQL and Django. I continue to see this error, and I cannot figure out where the exception is being raised:

Exception _mysql_exceptions.ProgrammingError: (2014, "Commands out of sync; you can't run this command now") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x20108150>> ignored

I have many “try” and “exception” blocks in my code - if an exception occurred in one of them, then I will see my own debugging messages. The above exception is obviously caught somewhere, since my program does not interrupt when the exception is thrown.

I am very puzzled, can someone help me?

+7
python django mysql exception
source share
5 answers

I had exactly this error (using MySQLdb and Django), and I found that the reason it was "ignored" was because it happened in the __del__ method. Exceptions in __del__ categorically ignored: object.__del__ datamodel

There seems to be no way to catch it from the stack (at least according to this topic ), but you can edit MySQLdb / cursors.py or monkey-patch to get your own __del__ which catches the exception and drags you into the pdb prompt or registers the full trace.

+7
source share

This is a Python bug.

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

There seems to be a problem with your MySQLdb Query.

+3
source share

I believe this error can occur if you use the same connection / cursor from multiple threads. However, I do not think that the creators of Django made such a mistake, but if you do something yourself, it can easily happen.

+2
source share

After you printed out a bunch of things and debugging, I realized what I was thinking. One of the libraries that I used did not close the connection or cursor. But this problem only occurs if I am sorting through a large amount of data. The problem is also very intermittent, and I still don't know who is throwing the command out of sync exception. But now that we have closed the connection and cursor, I no longer see errors.

+2
source share

Exceptions to object destructors ( __del__ ) are ignored, which indicates this message. If you execute any MySQL command without extracting the results from the cursor (for example, “create a procedure” or “insert”), the exception goes unnoticed until the cursor is destroyed. If you want to throw and catch an exception, explicitly cursor.close() somewhere before exiting the scope.

0
source share

All Articles