Also it takes roughly the same amount of time to check connection validity as opening a new connection, so it might be easier to open a new connection at the beginning of each request and close it in the end.
Here's the doc:
def ping(self, reconnect=False):
"""Checks whether or not the connection to the server is working.
If it has gone down, an automatic reconnection is attempted.
This function can be used by clients that remain idle for a long while, to
check whether or not the server has closed the connection and reconnect if
necessary.
Non-standard. You should assume that ping() performs an implicit rollback;
use only when starting a new transaction. You have been warned.
Args:
reconnect: Whether to perform an automatic reconnection.
Raises:
DatabaseError: The connection to the server is not working.
"""
No comments:
Post a Comment