I had a problem closing the connection as follows:
database = 'sed_database' conn = MySQLdb.Connect(host='remote_host', user='default', passwd='pass', db=database) try: try: cursor = conn.cursor() cursor.execute(sql_str) results = cursor.fetchall() except MySQLdb.Error, e: print "MySQL/Server Error using query: %s" % sql_str print "Using database: %s" % database raise e finally: if cursor: cursor.close() if conn: conn.close()
This gives:
Traceback (most recent call last): File "trass.py", line 579, in ? main(sys.argv) File "trass.py", line 555, in main old_rows, changes_list = auto_analyse_test(f, args.build, args.quiet, args.debug) File "trass.py", line 352, in auto_analyse_test last_analysed_build = get_sed_baseline_ref(test_file_name, old_delivery_stream) File "trass.py", line 151, in get_sed_baseline_ref results = execute_sql_query(sql, delivery_stream) File "trass.py", line 197, in execute_sql_query passwd='pass', db=database) File "C:\Python24\Lib\site-packages\MySQLdb\__init__.py", line 75, in Connect return Connection(*args, **kwargs) File "C:\Python24\Lib\site-packages\MySQLdb\connections.py", line 164, in __init__ super(Connection, self).__init__(*args, **kwargs2) _mysql_exceptions.InternalError: (3, "Error writing file 'D:\\MySQL_Datafiles\\Logfiles\\query. log' (Errcode: 9)")
The Python MySQLDB library information is as follows:
>>> print MySQLdb.get_client_info() 4.1.18 >>> print MySQLdb.__version__ 1.2.1_p2 >>> print MySQLdb.__revision__ 410
It is strange that:
- I checked the server and query.log exists and is being written by other processes.
- This code works through several iterations, and then it fails on a specific element.
- An exact query is performed using SQLyog and yields four results.
The error.log server says: "The connection was lost ... (Received error message reading messages)"
While the Traceback message appears indicating that the error was due to the creation of the connection, this does not happen until the connection is closed (or the termination of the function, which I assume closes it by default). I tried to put extra output or pauses between opening and closing. Every time an exception occurs at close. So what can cause this error when closing the connection?