• <small id='rGQHO'></small><noframes id='rGQHO'>

      1. <i id='rGQHO'><tr id='rGQHO'><dt id='rGQHO'><q id='rGQHO'><span id='rGQHO'><b id='rGQHO'><form id='rGQHO'><ins id='rGQHO'></ins><ul id='rGQHO'></ul><sub id='rGQHO'></sub></form><legend id='rGQHO'></legend><bdo id='rGQHO'><pre id='rGQHO'><center id='rGQHO'></center></pre></bdo></b><th id='rGQHO'></th></span></q></dt></tr></i><div id='rGQHO'><tfoot id='rGQHO'></tfoot><dl id='rGQHO'><fieldset id='rGQHO'></fieldset></dl></div>
          <bdo id='rGQHO'></bdo><ul id='rGQHO'></ul>
        <legend id='rGQHO'><style id='rGQHO'><dir id='rGQHO'><q id='rGQHO'></q></dir></style></legend>
      2. <tfoot id='rGQHO'></tfoot>

        pyodbc:如何重试从瞬态错误中恢复?

        pyodbc: How to retry to recover from Transient errors?(pyodbc:如何重试从瞬态错误中恢复?)

        1. <legend id='Yv1oh'><style id='Yv1oh'><dir id='Yv1oh'><q id='Yv1oh'></q></dir></style></legend>
        2. <tfoot id='Yv1oh'></tfoot>
              <bdo id='Yv1oh'></bdo><ul id='Yv1oh'></ul>

                1. <i id='Yv1oh'><tr id='Yv1oh'><dt id='Yv1oh'><q id='Yv1oh'><span id='Yv1oh'><b id='Yv1oh'><form id='Yv1oh'><ins id='Yv1oh'></ins><ul id='Yv1oh'></ul><sub id='Yv1oh'></sub></form><legend id='Yv1oh'></legend><bdo id='Yv1oh'><pre id='Yv1oh'><center id='Yv1oh'></center></pre></bdo></b><th id='Yv1oh'></th></span></q></dt></tr></i><div id='Yv1oh'><tfoot id='Yv1oh'></tfoot><dl id='Yv1oh'><fieldset id='Yv1oh'></fieldset></dl></div>

                  <small id='Yv1oh'></small><noframes id='Yv1oh'>

                    <tbody id='Yv1oh'></tbody>
                  本文介绍了pyodbc:如何重试从瞬态错误中恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Flask 上托管了一个 API.它在 Tornado 服务器后面运行.发生的情况是有时对 UI 所做的更改未反映在数据库中.此外,我运行的一些脚本会出现以下 3 个错误中的任何一个:

                  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:

                  1. pyodbc.Error: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]通信链接失败 (0) (SQLExecDirectW)')
                  2. pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionWrite (send()).(10054) (SQLExecDirectW)')
                  3. pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (recv()).(10054) (SQLExecDirectW)')

                  这是我的 Flask API 代码片段:

                  This is the snippet of my Flask API 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')
                  

                  是否可以在 cursor.execute 行中添加任何重试逻辑?我不知道如何使用 python 处理瞬时错误.请帮忙.

                  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.

                  推荐答案

                  根据我的经验,我觉得可能你可以尝试使用下面的代码来实现重试逻辑.

                  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)
                  

                  希望有帮助.

                  这篇关于pyodbc:如何重试从瞬态错误中恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Oracle: is there a tool to trace queries, like Profiler for sql server?(Oracle:是否有跟踪查询的工具,例如用于 sql server 的 Profiler?)
                  Splitting the string in sql server(在 sql server 中拆分字符串)
                  Composite Primary key vs additional quot;IDquot; column?(复合主键与附加“ID柱子?)
                  How to check if a database exists in SQL Server?(如何检查数据库是否存在于 SQL Server 中?)
                  How to determine total number of open/active connections in ms sql server 2005(如何确定 ms sql server 2005 中打开/活动连接的总数)
                  How to run a stored procedure in sql server every hour?(如何每小时在sql server中运行一个存储过程?)
                  <i id='MqQvQ'><tr id='MqQvQ'><dt id='MqQvQ'><q id='MqQvQ'><span id='MqQvQ'><b id='MqQvQ'><form id='MqQvQ'><ins id='MqQvQ'></ins><ul id='MqQvQ'></ul><sub id='MqQvQ'></sub></form><legend id='MqQvQ'></legend><bdo id='MqQvQ'><pre id='MqQvQ'><center id='MqQvQ'></center></pre></bdo></b><th id='MqQvQ'></th></span></q></dt></tr></i><div id='MqQvQ'><tfoot id='MqQvQ'></tfoot><dl id='MqQvQ'><fieldset id='MqQvQ'></fieldset></dl></div>
                2. <small id='MqQvQ'></small><noframes id='MqQvQ'>

                      <tbody id='MqQvQ'></tbody>
                      <legend id='MqQvQ'><style id='MqQvQ'><dir id='MqQvQ'><q id='MqQvQ'></q></dir></style></legend>
                        <tfoot id='MqQvQ'></tfoot>

                            <bdo id='MqQvQ'></bdo><ul id='MqQvQ'></ul>