8000 Option to add a timeout for ping · Issue #1169 · PyMySQL/PyMySQL · GitHub
[go: up one dir, main page]

Skip to content

Option to add a timeout for ping #1169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
smarden1 opened this issue Apr 29, 2024 · 1 comment
Open

Option to add a timeout for ping #1169

smarden1 opened this issue Apr 29, 2024 · 1 comment

Comments

@smarden1
Copy link

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.

@smarden1
Copy link
Author

I've taken a stab at this one (#1170). It's a little bit hacky, but is simple and does the job. Happy to revisit or change it in any way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0