pyodbc: How to retry to recover from Transient errors?

前端 未结 1 758
广开言路
广开言路 2020-12-07 04:07

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 th

相关标签:
1条回答
  • 2020-12-07 04:19

    Per my experience, I think may be you can try to use the code below to implement the retry logic.

    import time
    
    retry_flag = True
    retry_count = 0
    while retry_flag and retry_count < 5:
      try:
        cursor.execute(query, [args['type'], args['id']])
        retry_flag = False
      except:
        print "Retry after 1 sec"
        retry_count = retry_count + 1
        time.sleep(1)
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题