Skip to main content

retry utils

Project description

func-retry

📦 安装

pip install func-retry

💡 使用示例

Sync

from func_retry import retry


@retry(times=3, delay=1)
def fetch_data():
    print("Fetching data...")
    raise Exception("Failed to fetch")


fetch_data()

Async

import asyncio
from func_retry import retry


@retry(times=3, delay=1)
async def fetch_data_async():
    print("Fetching data asynchronously...")
    raise Exception("Async fetch failed")


asyncio.run(fetch_data_async())

Callback

def log_error(current_error, current_retry_times, args, kwargs):
    print(f"Func run failed with error: {current_error}")


@retry(times=3, callback=log_error)
def test_func():
    raise Exception("Test exception")


test_func()

🧩 API 说明

@retry(exc=Exception, times=3, delay=None, callback=None)

参数说明

参数名 类型 描述
exc Exception 或其子类 需要捕获并重试的异常类型,默认是 Exception
times Optional[int] 最大重试次数,默认为 3,若为 None 则无限重试直到成功
delay Optional[int] 每次重试之间的等待时间(秒),默认不延迟
callback Callable[[Exception, int, Tuple, Dict], Union[Awaitable, None]] 可选回调函数,在每次失败后调用

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

func_retry-0.1.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

func_retry-0.1.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file func_retry-0.1.1.tar.gz.

File metadata

  • Download URL: func_retry-0.1.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for func_retry-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fb8cef5898fe2c1410f9007b757d4e8332d692fa95b0d59efb852fba5c5813ac
MD5 014cba4047add79c563f73ed9cd1db14
BLAKE2b-256 fd112f8438ea4e277c9b34f8632c5ff1e1f8bdc377f1809e35e10532a62f87e2

See more details on using hashes here.

File details

Details for the file func_retry-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: func_retry-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.17

File hashes

Hashes for func_retry-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdcf89e4692e79b5273e923cebf66c284eb6761b13dbf687f480db85b700cb72
MD5 1ebd968e0737eda733873ef9257f825b
BLAKE2b-256 3e7df7880f16e32f123bc958907b418f65e0db722e66b93899e081999889af52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page