Re: How to set a driver-side query execution timeout
Hello Aaron,
Currently, there isn't a solution. This [Bug#115788](https://bugs.mysql.com/bug.php?id=115788) report tracks and documents known limitations that stop Connector/Python from proving a proper timeout workflow.
Once the limitations described in the report are addressed (a.k.a., the bug is fixed), you should be able to control both query and connection timeouts.
Now, if you really are on a mission here and don't mind relying on a temporary hack, you could access the protected attribute `_socket` and work it out:
```
with mysql.connector.connect(user="root", use_pure=True) as cnx:
cnx._socket.set_connection_timeout(1)
with cnx.cursor() as cur:
cur.execute("SELECT SLEEP(10)") # mysql.connector.errors.OperationalError will happen
print(cur.fetchall())
```
Expected output:
```
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at '127.0.0.1:7306', system error: The read operation timed out
````
NOTE: this snippet showcases how to manipulate a query timeout using an "informal"/"hacky" approach. Hope it helps.
Regards,
Oscar.
Subject
Written By
Posted
Re: How to set a driver-side query execution timeout
August 06, 2024 02:40PM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.