title: make python wait for stored procedure to finish executing
body: <p>I have a python script that uses pyodbc to call an MSSQL stored procedure, like so:</p>
  
  <pre><code>cursor.execute("exec MyProcedure @param1 = '" + myparam + "'")
  </code></pre>
  
  <p>I call this stored procedure inside a loop, and I notice that sometimes, the procedure gets called again before it was finished executing the last time. I know this because if I add the line</p>
  
  <pre><code>time.sleep(1)
  </code></pre>
  
  <p>after the execute line, everything works fine.</p>
  
  <p>Is there a more elegant and less time-costly way to say, "sleep until the exec is finished"?</p>
  
  <p><strong>Update (Divij's solution):</strong> This code is currently not working for me:</p>
  
  <pre><code>from tornado import gen
  import pyodbc
  
  @gen.engine
  def func(*args, **kwargs):
      # connect to db
      cnxn_str = """
      Driver={SQL Server Native Client 11.0};
      Server=172.16.111.235\SQLEXPRESS;
      Database=CellTestData2;
      UID=sa;
      PWD=Welcome!;
      """
      cnxn = pyodbc.connect(cnxn_str)
      cnxn.autocommit = True
      cursor = cnxn.cursor()
      for _ in range(5):
          yield gen.Task(cursor.execute, 'exec longtest')
  
      return
  
  func()
  </code></pre>