title: Python 3 pyodbc stored procedure not fully executing
body: <p>I'm working on a script for a monthly file load that requires the use of a stored procedure in our MS SQL database.</p>
  
  <p>When I call the stored procedure via pyodbc, it starts executing, but it never finishes. My pseudocode is as follows:</p>
  
  <pre><code>cursor = db.cursor()
  cursor.execute({'call stored_procedure'})
  cursor.commit()
  
  for n in range(1, 103):
      c2 = db.cursor()
      c2.execute('select IsFinished from '
                 'procedure_statuses where '
                 'procedure_name = "stored_procedure"')
      r = c2.fetchone()
      if r == True:
          c2.close()
          break
      c2.close()
      time.sleep(300)
  cursor.close()
  </code></pre>
  
  <p>procedure_status's StartDate is always changed at the beginning of the run, but the IsFinished is never changed and neither is the FinishedDate. These fields are all updated in the stored procedure, like so</p>
  
  <pre><code>update procedure statuses
      set IsFinished = 0, StartDate = GETDATE()
      where procedure_name = 'stored_procedure'
  
  /* TONS OF STORED PROCEDURE */
  
  update procedure_statuses
      set IsFinished = 1, FinishedDate = GETDATE()
      where procedure_name = 'stored_procedure'
  
  return
  </code></pre>
  
  <p>I'm noticing that there is a process existing for the second cursor (the "select IsFinished" bit) but not for the first one in the Activity Monitor.</p>
  
  <p>So, why is pyodbc starting the stored procedure but not finishing it?</p>
  
  <p>*EDIT: It should be noted, as well, that this is a fairly large stored procedure.  The execution time inside of MSSQL Server can last over 15 minutes. If this is a common problem with large stored procedures I'm really screwed because I have another one that can take a few hours that I need to trigger.</p>