Skip to main content

Generic background task handling for Air applications

Project description

AirTasks

Generic background task handling for Air applications

A lightweight library for managing background tasks in async Python applications, especially designed for Air web apps.

Features

  • 🔒 LRULockDict: Resource locking with automatic LRU eviction to prevent race conditions
  • 🚀 spawn_task: Helper to spawn fire-and-forget background tasks with automatic exception logging
  • 🔐 run_task_with_lock: Run tasks with automatic lock management

Installation

pip install airtasks

Or with uv:

uv add airtasks

Quick Start

1. Spawning Background Tasks

from airtasks import spawn_task

async def process_data(data_id: int):
    # Do expensive work
    await expensive_operation(data_id)

# Spawn it - exceptions are automatically logged
spawn_task(process_data(123), name="process-123")

2. Resource Locking with LRU Eviction

from airtasks import LRULockDict

# Create a lock dictionary (max 2000 locks in memory)
resource_locks = LRULockDict(max_size=2000)

# Use locks to prevent race conditions
async def process_resource(resource_id: int):
    async with resource_locks[resource_id]:
        # Only one task can process this resource at a time
        await do_work(resource_id)

4. Complete Example

Run the demo to see all features in action in tests/demo.py

just run

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Please open an issue or PR on GitHub.

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

airtasks-0.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

airtasks-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file airtasks-0.1.0.tar.gz.

File metadata

  • Download URL: airtasks-0.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for airtasks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6dc5f2fed85b67eb32d714cf0f1dd055db376c87fc3aecbd5874ebe558deb4b
MD5 36737ad1fa382468f8882faae561cf69
BLAKE2b-256 2756ac857f42980441fc8b7f29360dd2b38397c521fd4dc2a61131aef4d79e1a

See more details on using hashes here.

File details

Details for the file airtasks-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: airtasks-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for airtasks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 967c3329d7a42a20099e7523c37ba55fa26b7e1ee8df81d3a25df2374b435890
MD5 0ce5b7531a495f55ce623aaabb415ddf
BLAKE2b-256 fa28f8355c726ee90c2d4a993824a49b0ebbaa707fa64673e6099c58a67a158f

See more details on using hashes here.

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