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.3.tar.gz
(3.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file func_retry-0.1.3.tar.gz.
File metadata
- Download URL: func_retry-0.1.3.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
892aac4bc83c0c83573a40749153f3b5311d5e94efb20c1f46646a7c767994d9
|
|
| MD5 |
a86f77a79fd95c477f32f954a8b59d7f
|
|
| BLAKE2b-256 |
da4a3c13d309c2360d08151735be91279df247a32ed2fb0efdc11142ed483e9f
|
File details
Details for the file func_retry-0.1.3-py3-none-any.whl.
File metadata
- Download URL: func_retry-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
580c3d57bddf033f7f2ba346f52e2d3d0c48bb3be83fd2e7b0b340e418db17ac
|
|
| MD5 |
659660f89cc9d100dbda2e6dad953383
|
|
| BLAKE2b-256 |
d131051daadaab461dd58680a12fef6e227e6c4d9e68ecd071e1e59f793d63e0
|