Skip to main content

`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

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

  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

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

recoverable_async_task-0.2.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

recoverable_async_task-0.2.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file recoverable_async_task-0.2.1.tar.gz.

File metadata

  • Download URL: recoverable_async_task-0.2.1.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

Hashes for recoverable_async_task-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1bcce34c4e30dabaed9341b28689b070d6248a9bc948eda18bd8db5c4f2cc957
MD5 88e488fd06b346a0af47ce802ccc972a
BLAKE2b-256 2dbde43d26657d8feb3e0fe0720d45db9be35c8214dd6a737961e19aff3665b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for recoverable_async_task-0.2.1.tar.gz:

Publisher: publish-to-pypi.yml on Haskely/recoverable-async-task

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file recoverable_async_task-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for recoverable_async_task-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69257fd5a00cd94c3ecbbb58f715000a00c7c75ec59b1f122c4fefd3bb6d2c92
MD5 11bd9436804c045a53bef80cf0117e7b
BLAKE2b-256 16761fbdda6fb03b04f25c2c15ea291bb4ce39f3bc0851e02718cc9e15200320

See more details on using hashes here.

Provenance

The following attestation bundles were made for recoverable_async_task-0.2.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on Haskely/recoverable-async-task

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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