Tenacity 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.
Questions tagged [tenacity]
12 questions
4
votes
2 answers
Python retry with dynamic parameters
Tried this in the retrying and tenacity python libraries to no avail.
Retries are typically used with a decorator, for example as shown in metacode below:
class FooBar:
@retry(attempts=3)
def dosomething():
...
I want the retry…

Adam Hughes
- 14,601
- 12
- 83
- 122
3
votes
1 answer
Tenacity output the messages of retrying?
The code
import logging
from tenacity import retry, wait_incrementing, stop_after_attempt
import tenacity
@retry(wait=wait_incrementing(start=10, increment=10, max=100), stop=stop_after_attempt(3))
def print_msg():
logging.info('Hello')
…

ca9163d9
- 27,283
- 64
- 210
- 413
3
votes
0 answers
Best way to use httpx async client and tenacity?
I'm getting fairly different results with two different implementations.
Here is implementation 1
request_semaphore = asyncio.Semaphore(5)
async def _send_async_request(client: AsyncClient, method, auth, url, body):
async with request_semaphore:
…

JTa
- 181
- 1
- 12
2
votes
1 answer
tenacity retrying with exception handler
Can tenacity handle this or should I implement retry wrapper myself if I need to catch exception do a callback and get back to next try?
send → fetch error → if recoverable → run callback → try send again
When I use a simple case with this code,…

Rostislav Aleev
- 351
- 5
- 19
2
votes
1 answer
python3 try/except appears to fail when using a tenacity decorator
Trying to get tenacity to work with a requests function to implement a retry/backoff then return HTTP status if all the retries fail. It seems that I can either get the retry working or use try/except, but not both at the same time. Wrapping in…

js_cpnet
- 21
- 3
1
vote
1 answer
Custom Retry behaviour per each error with tenacity library
I would like to make a custom retry behaviour for different error types.
For example if I receive a 401 Error I would like to call a token refresh before retring a request. If I receive a 500 I would like to retry the error after some time. etc.
Is…

Eduard6421
- 295
- 1
- 11
1
vote
1 answer
How to overcome Rate limit error while working with GPT3 Models using Tenacity
In my situation I am trying to pass a prompt using a helper function to the actual GPT3 models, in my case text-ada-001 and then eventually applying it on a pandas column using the following code. but I am recovering the following error:
def…

Django0602
- 797
- 7
- 26
1
vote
0 answers
Logging python tenacity retry_state with logger from outer scope
I have a module that includes a utility function with a tenacity retry tag
from tenacity import retry, stop_after_attempt, wait_random
def log_attempt_number(logger, retry_state):
logger.info(f"Attempt number {retry_state}")
logger.info("Logger…

OJT
- 887
- 1
- 10
- 26
0
votes
0 answers
Tenacity retry module understanding
I have written multiple except cases at the end of the code.
Can anyone explain exactly whats wrong with my code, whats the correct way to use tenacity ?
also I coulnt understand the use of reraise = True and False.
import requests
from tenacity…

coder_boy
- 11
- 1
0
votes
1 answer
Getting error message from tenacity retry_state.outcome.result() results in program termination
I'm using the python tenacity library to do exponential backoff of a funtion.
import tenacity
def log_attempt_number(retry_state):
print(f"Retrying: {retry_state.attempt_number}...")
…

Ben Alan
- 1,399
- 1
- 11
- 27
0
votes
1 answer
Disable Tenacity for loop `for attempt in Retrying` in unit tests
I am writing unit tests and want to disable tenacity, I've previously been able to disable tenacity when its a decorator ie:
@retry(stop=stop_after_attempt(3),wait=wait_fixed(5))
def function_that_retries(param) -> None:

Mia Altieri
- 19
- 1
- 4
0
votes
1 answer
Does setting socket timeout cancel the initial request
I have a request that can only run once. At times, the request takes much longer than it should.
If I were to set a default socket timeout value (using socket.setdefaulttimeout(5)), and it took longer than 5 seconds, will the original request be…

beano
- 932
- 1
- 15
- 28