-
-
Notifications
You must be signed in to change notification settings - Fork 307
Closed
Description
For some reason, tenacity's statistics don't calculate the elapsed time like I would expect. I would expect the below example to log that 3.5 sec elapsed, but delay_since_first_attempt says 2 sec. I think the statistics don't get updated with the time elapsed following the second to last attempt if the last attempt was successful.
In [40]: attempt_num_list = [1]
In [41]: @retry(stop=stop_after_delay(10), wait=wait_fixed(1))
...: def succeed_on_attempt(success_attempt_num, execution_time_s=0.5):
...: print("Attempt {}".format(attempt_num_list[0]))
...: print("Start {}".format(time.time()))
...: time.sleep(execution_time_s)
...: if attempt_num_list[0] != success_attempt_num:
...: attempt_num_list[0] += 1
...: print("Stop {}".format(time.time()))
...: raise Exception
...: print("Stop {}".format(time.time()))
...:
In [42]: succeed_on_attempt(3)
Attempt 1
Start 1623168327.531153
Stop 1623168328.031927
Attempt 2
Start 1623168329.0345838
Stop 1623168329.5350487
Attempt 3
Start 1623168330.536717
Stop 1623168331.038352
In [43]: print(succeed_on_attempt.retry.statistics)
{'start_time': 1459638.89, 'attempt_number': 3, 'idle_for': 2, 'delay_since_first_attempt': 2.0}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels