Skip to main content

retry utils

Project description

func-retry

PyPI version License

📦 安装

你可以通过 pip 安装:

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]] 可选回调函数,在每次失败后调用

📝 许可证

本项目采用 MIT License。详见 LICENSE 文件。

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.0.tar.gz (6.1 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.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for func_retry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b66b4d57de51ee60fc3aa842bfe3b46cfc16bfe9b1b9e7d3612331e8113a36d
MD5 ed1d701234fb751fda7b6e1ac25698ee
BLAKE2b-256 baf2a2aaa20f5b1f80228596dae51b1b2d6a7d9f99fac311d6fe7b8fb1433e86

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for func_retry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5bc07533e707ef93bfd999163d78df11fc09562cbf4aa1d6fcf089c4d788fae
MD5 63a059cf2dcb4ba3b28dc21cd6938f48
BLAKE2b-256 4fb00fee9a7380b5ac50d7ee9a95915374370dc21b0823590beaab09fd215a02

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