gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:43:57 25 4
gpt4 key购买 nike

我想澄清一下预 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 theinitial connect will fail and the error for failure to connect will bepropagated normally. In the uncommon situation that the database isavailable for connections, but is not able to respond to a “ping”, the“pre_ping” will try up to three times before giving up, propagatingthe database error last received.

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com