Adds a new option for adding a timeout for ping #1170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Attempt at #1169
====
The pymsql library currently supports a timeout for connect, reading, and writing, but there isn't a specific timeout for ping.
There's an interesting interaction between this library and a more high-level one, such as sqlalchemy. Many of the default classes for connection pools in sqlalchemy often allow for a pool_pre_ping option, which will ping the connection while checking it out of the pool. If the connection does not respond or is determined to be unconnected, then the pool will fetch a brand new connection.
Conceptually, this pre-pinging is essentially acting as a connect, however there is no way to timeout quickly if the connection is hangs or is in a bad state. One could set the read/write timeout to be low, but in practice this is difficult to do, as once a transaction is open or a connection is in use, then its reasonable to tolerate some read/write lag.
While it isn't necessarily the responsibility of this library to provide a ping that uses the connect timeout, it would be great to have an option to do so.