python - 如何处理 SQLAlchemy 断开连接?
问题描述
我正在使用 sqlalchemy 建立与 Presto 的连接,然后使用 dask 并行读取查询。问题是由于TimeoutError
. 将 SQLAlchemy 引擎传递给 Pandas 时实现重试逻辑的最佳方法是什么?
代码示例:
import dask.dataframe as dd
from dask import delayed
def parallelize_query(date):
engine = create_engine(f'presto://{user}:{password}@{host}:{port}/{catalog}/{schema}',
connect_args={'protocol': 'https',
'requests_kwargs': {'verify': key}})
q = query.format(date)
data = pd.read_sql(q, conn)
engine.dispose()
return data
ddf = dd.from_delayed([delayed(parallelize_query)(d) for d in recent_dates])
错误:
ConnectionError: HTTPSConnectionPool(host='<host>', port=<port>): Max retries exceeded with url: /v1/statement/executing/20200427_231652_00087_rfnzc/yb90eab8fdeee4de5656afabc011dd8724e77bdcb/13761 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x913f95e90>: Failed to establish a new connection: [Errno 60] Operation timed out'))
解决方案
推荐阅读
- javascript - 如何在实时搜索表上应用奇数和偶数?
- c# - 在 NEST (ElasticSearch) 中使用 searchResponse 中的 storedFields 时出错
- reactjs - 如何使用 redux-persist 同时持久化到 localStorage 和 sessionStorage?
- .net-core - 从列表中删除项目不会刷新正确的组件
- python - 将类型/类实例作为参数传递给类构造函数?
- python - 如何使用numpy将除前n个值之外的矩阵(二维数组)的所有值清零?
- reactjs - 反应 setState 工作然后变得未定义
- java - java - 如何比较两个txt文件中的元素并将它们合并到一个文件中?
- c# - Password_Verify 哈希密码问题
- python - 什么是 tf.losses.absolute_difference 的替代品