Skip to main content

recoverable-async-task

English | 中文文档

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
        show_progress=True,                           # Show progress bar
        force_rerun=False,                            # Don't force rerun completed tasks
    )
    async def task(id: int) -> dict | None:
        await asyncio.sleep(0.1)
        try:
            if random.randint(1, 2) == 1:
                raise Exception(f"Task {id=} failed!")
            return {"id": id, "data": f"Task {id=} finished!"}
        except Exception as e:
            print(f"Error: {e}")
            return None

    # 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
  • 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:

  1. Successfully completed task states are saved in the checkpoint file
  2. When rerunning the program, completed tasks are automatically skipped
  3. Only previously failed or unexecuted tasks will be processed
  4. 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

Metadata

Release files for recoverable-async-task 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for recoverable-async-task 0.2.4
File Size Uploaded
recoverable_async_task-0.2.4.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for recoverable-async-task 0.2.4
File Interpreter ABI Platform
recoverable_async_task-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 9.9 kB

Release files / recoverable_async_task-0.2.4.tar.gz

Download URL recoverable_async_task-0.2.4.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a29196674e8489a64f4526389e6044f547e0721272a4f9da8121fcd83d582750
BLAKE2b-256 checksum
How to use checksums
97441bcb628495caa3b7fd3a61519c0735f934ce5855f42a90488f21297e66e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 7, 2025.

Transparency log

Release files / recoverable_async_task-0.2.4-py3-none-any.whl

Download URL recoverable_async_task-0.2.4-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b096cba5bd0475d0fbc3db529f55fc7ac6baa1817b106dce5ac7c9caf2049a5
BLAKE2b-256 checksum
How to use checksums
db184c69ba7c1dd384f8ee4db3a5fc966ce0bf61c4c43fabdc7a500f045f594f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 7, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page