rholder / retrying

Retrying is an Apache 2.0 licensed general-purpose retrying library, written in Python, to simplify the task of adding retry behavior to just about anything.
Apache License 2.0
1.91k stars 157 forks source link

stop_max_delay doesn't work as expected #56

Open kalessin opened 8 years ago

kalessin commented 8 years ago

I am not sure how stop_max_delay is intended to work, but I would expect it would stop retry after have been retrying more than the given time with that parameter. However, actually it works very differently: it just disable retry if the script has been run for more than the given time. This can be easily reproduced with this script:

import time                                                                                                                                                                     
import sys 
from retrying import retry

def retry_on_exception(exception):
    print 'Retrying....'
    return True

@retry(retry_on_exception=retry_on_exception, stop_max_delay=10000, wait_fixed=1000)
def test(sleep):
    time.sleep(sleep)
    assert False

if __name__ == '__main__':
    test(int(sys.argv[1]))

if I run

python test.py 0

you will get 10 retries, one per second, as expected. In this case, the exception is raised as soon as the script starts, that is why the problem is not seen. However, if you run

python test.py 12

(so exception will be raised 12 seconds after the script started), you won't get any retry.

alexyr commented 7 years ago

It works like global timeout. If your single try will be longer than stop_max_delay, it will not be executed again.