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

Does the pre ping feature in SqlAlchemy db pools automatically reconnect and send the SQL command in case the pre ping check fails?

我想澄清一下预 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.