I'm using MySQLdb
in python to connect to a remote database and execute a query. So far so good. However, it's possible that, for any number of reasons, there simply isn't a MySQL server (or indeed any server) at the designated IP address. In these cases, at the moment MySQLdb
hangs indefinitely. This isn't ideal, I'd prefer to be able to set a timeout which if exceeded would allow me to raise and exception and get on with my life.
Is there a simple way to do this?
You can pass connect_timeout
argument to MySQLdb.connect
function. Quote from docs:
connect_timeout
Abort if connect is not completed within given number of seconds.
Default: no timeout (?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With