raito.utils.helpers.retry_method module

async raito.utils.helpers.retry_method.retry_method(func, *args, **kwargs)[исходный код]

Call an async function and retry it on Telegram errors.

Pass the coroutine function together with its arguments.

Example:

await rt.retry(bot.send_message, chat_id, "text")
await rt.retry(message.answer, "text")

Retries on TelegramRetryAfter (honouring the server-provided retry_after) and on network/server errors (TelegramNetworkError, TelegramServerError) using exponential delay. Any other exception is raised immediately.

Параметры:
  • func (Callable[[~P], Awaitable[T]]) – A coroutine function to call on each attempt.

  • args (~P) – Positional arguments forwarded to func.

  • kwargs (~P) – Keyword arguments forwarded to func.

Результат:

Result of the func.

Исключение:

Exception – If all attempts fail or a non-RetryAfter exception is raised.

Тип результата:

T

Устарело, начиная с версии 1.6.0: Passing an already-created coroutine (rt.retry(bot.send_message(...))) is deprecated and will stop working in 1.8.0. It is awaited only once and cannot be retried. Pass the function and its arguments instead: rt.retry(bot.send_message, chat_id, text).