`recoverable-async-task` is a Python library that streamlines the handling of asynchronous tasks through its `RecoverableAsyncTask` class, with the added benefit of **supporting task checkpointing and resumption**. This feature ensures that tasks can pick up from where they left off in the event of unexpected failures.
Project description
recoverable-async-task
recoverable-async-task is a lightweight Python library that focuses on providing JSONL-based checkpoint recovery functionality for async tasks. It automatically records task execution states, allowing tasks to resume from where they left off after interruption, making it ideal for handling large-scale, time-consuming asynchronous tasks.
Installation
pip install recoverable-async-task
Quick Start
Here's a simple example demonstrating how to use the make_recoverable decorator to handle async tasks:
import asyncio
import random
from recoverable_async_task import make_recoverable
async def main():
@make_recoverable(
storage_path_name=".checkpoint/example-task", # Checkpoint file storage path
raise_on_error=False, # Don't raise exceptions on task failure
show_progress=True, # Show progress bar
force_rerun=False, # Don't force rerun completed tasks
)
async def task(id: int) -> dict:
await asyncio.sleep(0.1)
if random.randint(1, 2) == 1:
raise Exception(f"Task {id=} failed!")
return {"id": id, "data": f"Task {id=} finished!"}
# Execute tasks and collect results
task_ids = list(range(10)) # Create 10 test tasks
async for result in task.as_completed(task_ids):
print(result)
if __name__ == "__main__":
asyncio.run(main())
Configuration Parameters
The make_recoverable decorator supports the following parameters:
storage_path_name: str, optional- Storage path for checkpoint files
- Defaults to the decorated function's name
raise_on_error: bool, defaults to True- Controls whether to raise exceptions on task failure
- When False, skips failed tasks and continues execution
show_progress: bool, defaults to True- Whether to display a progress bar
- Shows completed/total tasks count
force_rerun: bool, defaults to False- Whether to force rerun completed tasks
- Useful for scenarios requiring recalculation
Checkpoint Recovery Mechanism
When task execution fails:
- Successfully completed task states are saved in the checkpoint file
- When rerunning the program, completed tasks are automatically skipped
- Only previously failed or unexecuted tasks will be processed
- This process can be repeated until all tasks are completed
Concurrency Control
This library focuses on providing checkpoint recovery functionality. For more powerful concurrency control features, we recommend using the adaptio library.
Development Guide
This project uses uv for environment management:
# Install dependencies
uv sync
# Run tests
pytest
# Format code
pre-commit run --all-files
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 recoverable_async_task-0.2.0.tar.gz.
File metadata
- Download URL: recoverable_async_task-0.2.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6689f80e37f231cee5169ad0c95d887266bf781e68cac29a318ae40b650ae154
|
|
| MD5 |
617179c8f4afbcf3c0919e06b29ea8cb
|
|
| BLAKE2b-256 |
5567d848cd31b3225c5ce1ab2bc3c0afcfe15b0693f97873eb0306641b71ab03
|
Provenance
The following attestation bundles were made for recoverable_async_task-0.2.0.tar.gz:
Publisher:
publish-to-pypi.yml on Haskely/recoverable-async-task
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
recoverable_async_task-0.2.0.tar.gz -
Subject digest:
6689f80e37f231cee5169ad0c95d887266bf781e68cac29a318ae40b650ae154 - Sigstore transparency entry: 157243390
- Sigstore integration time:
-
Permalink:
Haskely/recoverable-async-task@7953468e83b4a208f9389f8636b3f6db1de2dd72 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Haskely
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@7953468e83b4a208f9389f8636b3f6db1de2dd72 -
Trigger Event:
push
-
Statement type:
File details
Details for the file recoverable_async_task-0.2.0-py3-none-any.whl.
File metadata
- Download URL: recoverable_async_task-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6add10e1a714aea2cd413c78ec9f767f69805ccc5c17a0f48f45f23d11ce8de9
|
|
| MD5 |
592b270288059b20406e1cdfbebe9c23
|
|
| BLAKE2b-256 |
0983d610f100ea465fe901a374de185b90bde6c083fbf9ae79ebf28cdeb3ebce
|
Provenance
The following attestation bundles were made for recoverable_async_task-0.2.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on Haskely/recoverable-async-task
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
recoverable_async_task-0.2.0-py3-none-any.whl -
Subject digest:
6add10e1a714aea2cd413c78ec9f767f69805ccc5c17a0f48f45f23d11ce8de9 - Sigstore transparency entry: 157243391
- Sigstore integration time:
-
Permalink:
Haskely/recoverable-async-task@7953468e83b4a208f9389f8636b3f6db1de2dd72 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Haskely
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@7953468e83b4a208f9389f8636b3f6db1de2dd72 -
Trigger Event:
push
-
Statement type: