I have this code where I am executing a sql
statement using pymysql
library:
try:
conn = pymysql.connect(db_endpoint, user=db_username,
passwd=db_password, db=db_name, connect_timeout=5)
cur = conn.cursor()
result = cur.execute(sql)
resultSet1 = cur.fetchall()
except:
print('ERROR: Unexpected error: Could not connect to MySql instance.')
logger.error("ERROR: Unexpected error: Could not connect to MySql instance.")
sys.exit()
Now what I want to do is track how long this query takes to execute and if it exceeds say more than 2 minutes then stop the execution and exit with a print message for timeout. I know I can use default_timer()
to initiate a timer in python but I am unable to make a continuous check to see as soon as it hits 2 minutes it should stop the execution. How can I do that?