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: An Asynchronous Task Processing Library

中文文档 | English

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.

Quick Start Guide

To install the library, use the following command:

pip install recoverable-async-task

The following is a simple illustration of how to utilize the RecoverableAsyncTask library to manage concurrent tasks and enable checkpointing and resumption:

import asyncio

from recoverable_async_task import RecoverableAsyncTask


async def main():
    async def task(id: int | str):
        import random

        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!"}

    # 创建 RecoverableAsyncTask 实例
    re_async_task = RecoverableAsyncTask(
        task,
        max_workers=10,
        max_qps=10,
        retry_n=3,
        checkpoint_path_name="save-dir/my-example-task",
    )

    # 推送任务以并发处理
    for i in range(100):
        re_async_task.push(i)

    # 收集并打印结果
    async for result in re_async_task.collect_results():
        print(result)


asyncio.run(main())

You may notice that even with retry_n=3 set, some tasks may still fail due to random issues. In such cases, you can simply execute the tasks again, and they will automatically read the checkpoint file and resume from where they were interrupted. You can repeat this process manually or programmatically until all tasks are successfully completed.

Contributing Guidelines

If you wish to contribute to the recoverable-async-task library, please follow the setup instructions below to prepare your development environment:

source setup-env-rye.sh

plan

[] Support custom progress bar statistics [] Supports passing in custom error handling logic

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.1.9.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

recoverable_async_task-0.1.9-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for recoverable_async_task-0.1.9.tar.gz
Algorithm Hash digest
SHA256 073766af7ac0c265947b8701fc10dcf41b3f309892e58e9f17d3b5b425dec364
MD5 877c3e968c056cf6a764497928647d6c
BLAKE2b-256 17ed0c56a2bcfb203e91631b434ee1163ce3275437f95d04c1ab47dfbd66c41a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for recoverable_async_task-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e8ee459968740bff8292e95070ae724079b79f1b0cfb40f23d1e8b26a3216106
MD5 53c41f4e0460367388c5aee32afedd28
BLAKE2b-256 2a6c77564acaadc69345a3a2610e9f0250891ec5b4a04ac6c81d427d89b33c91

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page