title: Python mysqldb error closing connection
body: <p>I'm having a problem when closing a connection as follows:</p>
  
  <pre><code>   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()
  </code></pre>
  
  <p>This gives:</p>
  
  <pre><code> 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)")
  </code></pre>
  
  <p>Python's MySQLDB library info is as follows:</p>
  
  <pre><code>&gt;&gt;&gt; print MySQLdb.get_client_info()
  4.1.18
  &gt;&gt;&gt; print MySQLdb.__version__
  1.2.1_p2
  &gt;&gt;&gt; print MySQLdb.__revision__
  410
  </code></pre>
  
  <p>What is strange is that:</p>
  
  <ul>
  <li>I've checked on the server and query.log exists and is being written to by other processes.</li>
  <li>This code works through several iterations, then on a particular item it fails.</li>
  <li>The exact query runs fine via SQLyog and yields four results.</li>
  </ul>
  
  <p>The server error.log says "Aborted connection... (Got an error reading comminication packets)"</p>
  
  <p>While the Traceback appears to show the error being associated with the connection creation, it doesn't occur until the connection is closed (or the function ends, which I guess closes it by default). I've tried putting extra output or pauses between open and close. Every time the exception occurs on the close. So what could cause this error on closing the connection?</p>