title: python MySQL Connector
body: <p>I'm playing with big data in Python and MySQL.</p>
  
  <p>I've a got a huge table, I need to insert new rows while I'm fetching query's results.</p>
  
  <p>I've got this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "recsys.py", line 53, in &lt;module&gt;
      write_cursor.executemany(add_sim, data_sims)
    File "/Library/Python/2.7/site-packages/mysql/connector/cursor.py", line 603, in executemany
      self._connection.handle_unread_result()
    File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 1057, in handle_unread_result
      raise errors.InternalError("Unread result found")
  mysql.connector.errors.InternalError: Unread result found
  </code></pre>
  
  <p>The code is the following one:</p>
  
  <pre><code>#!/usr/bin/env python
  # -*- coding: utf-8 -*-
  
  import logging
  import mysql.connector
  
  import numpy
  import scipy
  from scipy.spatial import distance
  
  logging.basicConfig(filename='recsys.log', level=logging.INFO)
  
  cnx = mysql.connector.connect(user='...', password='...', database='...')
  
  cursor = cnx.cursor(dictionary=True)
  write_cursor = cnx.cursor()
  
  
  query = ("...")
  
  cursor.execute(query)
  
  while True:
      rows = cursor.fetchmany(100)
      if not rows:
          break
  
      add_sim = ("...")
      data_sims = []
  
      for row in rows:
          f1 = row['f1']
          f2 = row['f2']
          v1 = [[row['a1'], row['b1'], row['c1']]]
          v2 = [[row['a2'], row['b2'], row['c2']]]
  
          c = 1 - scipy.spatial.distance.cdist(v1, v2, 'cosine')
  
          if c &gt; 0.8:
  
              data_sim = (f1, f2, c)
              data_sims.append(data_sim)
  
      write_cursor.executemany(add_sim, data_sims)
      cnx.commit()
  
  cursor.close()
  
  cnx.close()
  </code></pre>
  
  <p>I know I could use a buffered connection to mysql, but it's not a good choice in my case because of how really big my table is!</p>