Python Retry Using The Tenacity Module
I'm having having difficulty getting the tenacity library to work as expected. The retry in the following test doesn't trigger at all. I would expect a retry every 5 seconds and fo
Solution 1:
I suppose that tenacity
detects failures by handling exceptions. In your code the exception is logged and then discarded. So, for tenacity
, your call is actually successful. You should re-raise this exception to get the expected behavior. Like this:
@tenacity.retry(wait=tenacity.wait_fixed(5))
def connect():
try:
client.connect(HOST, int(PORT), USER)
logging.info("Successful connection to remote server")
except Exception:
logging.error("Cannot connect to remote server")
raise
Post a Comment for "Python Retry Using The Tenacity Module"