本文介绍了sqlalchemy pymssql“由对等方重置连接"恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行cherrypy Web服务,想知道最好的选择是通过"sqlalchemy"从对等连接重置"恢复pymssql连接.现在,我必须重新启动Web服务.
I'm running a cherrypy webservice and wondering what the best option is to recover from "connection reset by peer" for a pymssql connection via sqlalchemy. Right now I have to restart the webservice.
推荐答案
这似乎是pymssql的is_disconnect()方法中的错误,它忽略了TCP连接和超时失败,使光标处于不满意的状态;参见 http://www.sqlalchemy.org/trac/ticket/2172 .现在,您可以按照以下方式进行猴子补丁:
This seems to be a bug in the is_disconnect() method for pymssql where it ignore TCP connection and timeout failures, leaving the cursor in an unhappy state; see http://www.sqlalchemy.org/trac/ticket/2172. For now, you can monkey-patch as:
from sqlalchemy.dialects.mssql import pymssql
def is_disconnect(self, e):
for msg in (
"20003",
"20004",
"Error 10054",
"Not connected to any MS SQL server",
"Connection is closed"
):
if msg in str(e):
return True
else:
return False
pymssql.MSDialect_pymssql.is_disconnect = is_disconnect
这篇关于sqlalchemy pymssql“由对等方重置连接"恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!