python - 如果预 ping 检查失败,SqlAlchemy 数据库池中的预 ping 功能是否会自动重新连接并发送 SQL 命令?

标签 python sqlalchemy connection-pooling

我想澄清一下预 ping 功能如何与 SqlAlchemy 数据库池一起使用。假设我尝试使用数据库池对我的数据库进行 SQL 查询。如果 db pool 发送一个 pre ping 来检查连接并且连接断开,它会自动处理吗?通过处理我的意思是它重新连接然后发送 SQL 查询?还是我必须在我的代码中自己处理这个问题?

谢谢!

最佳答案

来自 the docs ,是的,过时的连接是透明处理的:

The calling application does not need to be concerned about organizing operations to be able to recover from stale connections checked out from the pool.

...除非:

If the database is still not available when “pre ping” runs, then the initial connect will fail and the error for failure to connect will be propagated normally. In the uncommon situation that the database is available for connections, but is not able to respond to a “ping”, the “pre_ping” will try up to three times before giving up, propagating the database error last received.

关于python - 如果预 ping 检查失败,SqlAlchemy 数据库池中的预 ping 功能是否会自动重新连接并发送 SQL 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66692243/

相关文章:

python - SQLAlchemy 多对多过滤行按 child 的数量

java - 配置 Hibernate 以使用 Glassfish 连接池

java - 如何使用ResetAbandonedTimer避免由于removeAbandonedTimeout而关闭连接

python - Matplotlib + Latex 葡萄牙语渲染标签

python - 如何使用公共(public)列作为引用将数据从数据框的列复制到另一个数据框?

python - 我如何在 Python 中捕获 NameError?

Python请求或urllib读取超时,URL编码问题?

python - 使用 sqlalchemy 创建表

java - 像 Atomikos 这样的 JTA 提供者和像 HikariCP 这样的连接池之间有什么关系?

python - SqlAlchemy UserDefinedType 基于内置类型,带有附加方法