--- id: aiojobs version: "1.4.0" license: Apache 2 license_treatment: permissive maintenance: active --- # aiojobs — Job scheduler for managing background tasks (asyncio) License: permissive · Maintenance: active · Downloads: 354.1K/mo ## What it is and what it does aiojobs is a task scheduler for asyncio applications that manages the lifecycle of background jobs spawned during runtime. It solves the problem of uncontrolled task cancellation during application shutdown by providing a context manager that tracks all spawned tasks and waits for them to complete before closing. The library includes a Scheduler class that accepts coroutines via spawn(), tracks their execution, and ensures graceful termination. The package is typically used in asyncio web applications (especially with aiohttp) to run background work—such as cleanup, notifications, or long-running operations—without losing tasks on shutdown. It also provides a shield() method to protect tasks from cancellation while keeping them tracked, solving a gap in asyncio.shield() that loses visibility of shielded tasks. The single runtime dependency (async-timeout) keeps installation lightweight. Use it for: - Run background cleanup or maintenance tasks in web handlers without losing them on shutdown - Spawn multiple long-running coroutines and ensure all complete before application exit - Shield critical tasks from cancellation while maintaining scheduler visibility for graceful shutdown - Integrate background job management into aiohttp.web applications via the built-in aiohttp plugin - Manage task lifecycle in asyncio applications where manual task tracking is error-prone ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. aiojobs provides a scheduler for spawning and managing background asyncio tasks with controlled lifecycle, including graceful shutdown and task shielding from cancellation. Yes. aiojobs is actively maintained, production-stable, has no known vulnerabilities, and solves a real problem in asyncio applications—uncontrolled task loss during shutdown. Low install friction and permissive licensing make it a safe, practical choice for any asyncio project needing reliable background task management. ## Install pip install aiojobs uv add aiojobs poetry add aiojobs ## Installing aiojobs Before you install: Low install friction with a single runtime dependency (async-timeout). Actively maintained with recent commits and stable production status across Python 3.9–3.13. License in practice: Licensed under Apache 2 (permissive), allowing free use, modification, and distribution in both open and proprietary projects with minimal restrictions. Quickstart: pip install aiojobs import asyncio import aiojobs async def background_task(delay): await asyncio.sleep(delay) async def main(): async with aiojobs.Scheduler() as scheduler: await scheduler.spawn(background_task(1.0)) await asyncio.sleep(0.5) asyncio.run(main()) Requires Python 3.9 or later; asyncio is built-in but the application must use async/await syntax. Verify before relying: - Whether the scheduler supports priority queues or task ordering beyond FIFO spawn order - Maximum recommended number of concurrent jobs before performance degrades - Whether aiohttp integration is required or optional for core scheduler functionality ## Package facts - License: Apache 2 (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 354.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags asyncio background task scheduler, manage concurrent async jobs, asyncio task lifecycle control, background task queue asyncio, async job scheduling, graceful asyncio shutdown, shield asyncio tasks, asyncio, background-jobs, task-scheduling [View on SkillFed](https://skillfed.io/packages/aiojobs) · [View on PyPI](https://pypi.org/project/aiojobs/)