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] |
每次重试之间的等待时间(秒),默认不延迟 |
default |
Optional[Any] |
最终默认返回值。如果未设置,则会抛出运行中的异常 |
print_exc |
bool |
打印函数运行异常信息 |
callback |
Callable[[Exception, int, Tuple, Dict], Union[Awaitable, None]] |
可选回调函数,在每次失败后调用 |
Metadata
Release files for func-retry 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| func_retry-0.1.4.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| func_retry-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / func_retry-0.1.4.tar.gz
| Download URL | func_retry-0.1.4.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62a811cac17fc44ed2adac89a74bdc1dd2c57c5c8ec87d6176e36e066e77fec6
|
|
BLAKE2b-256 checksum How to use checksums |
9ec2f227c4d73762d9245bcb69c5abaa81eea9d5babd84a8339c2f717cd11f0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|
Release files / func_retry-0.1.4-py3-none-any.whl
| Download URL | func_retry-0.1.4-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f8b1ea2a86d1e14295a88853fc8a83e5dfca710141e52deb5ef7d41640f74a5
|
|
BLAKE2b-256 checksum How to use checksums |
07d31902654733ca9cfb7f03cf436e776ba0b82e0fb797fb1b0eea50b716f0b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.13
|