Skip to content

Python function retry

tenacity

python
import tenacity


@tenacity.retry(stop=tenacity.stop_after_attempt(3), wait=tenacity.wait_fixed(1))
def my_function():
    try:
        print('hi')
        print(4/0)
    except:
        raise Exception("error")

try:
    my_function()
except:
    print('failed')