title: pyodbc: How to retry to recover from Transient errors?
body: <p>I've an API hosted on Flask. It runs behind a Tornado server. What is happening is that sometimes changes made on the UI are not reflected in the database. Also a few of the scripts I have running gives any of the 3 following errors:</p>
  
  <ol>
  <li>pyodbc.Error: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Communication link failure (0) (SQLExecDirectW)')</li>
  <li>pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()). (10054) (SQLExecDirectW)')</li>
  <li>pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (recv()). (10054) (SQLExecDirectW)')</li>
  </ol>
  
  <p>This is the snippet of my Flask API code:</p>
  
  <pre><code>class Type(Resource):
  
      def put(self):
          parser = reqparse.RequestParser()
          parser.add_argument('id', type = int)
          parser.add_argument('type', type = int)
          args = parser.parse_args()
  
          query = """
          UPDATE myDb SET Type = ? WHERE Id = ?
          """
  
          connection = pyodbc.connect(connectionString)
          cursor = connection.cursor()
          cursor.execute(query, [args['type'], args['id']])
          connection.commit()
          cursor.close()
          connection.close()
  
  api.add_resource(Type, '/type')
  </code></pre>
  
  <p>Is there any retry logic I can add on the cursor.execute line? I've no idea how to deal with transient errors with python. Please help.</p>