aiojobs: Jobs scheduler for managing background task

The library gives controlled way for scheduling background tasks for asyncio applications.


$ pip3 install aiojobs

Usage example

import asyncio
import aiojobs

async def coro(timeout):
    await asyncio.sleep(timeout)

async def main():
    scheduler = await aiojobs.create_scheduler()
    for i in range(100):
        # spawn jobs
        await scheduler.spawn(coro(i/10))

    await asyncio.sleep(5.0)
    # not all scheduled jobs are finished at the moment

    # gracefully close spawned jobs
    await scheduler.close()


For further information read Quickstart, Introduction and API.

Integration with aiohttp.web

from aiohttp import web
from aiojobs.aiohttp import setup, spawn
import aiojobs

async def handler(request):
    await spawn(request, coro())
    return web.Response()

app = web.Application()
app.router.add_get('/', handler)

or just

from aiojobs.aiohttp import atomic

async def handler(request):
    return web.Response()

Source code

The project is hosted on GitHub:

Please feel free to file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.

Communication channels

aio-libs google group:!forum/aio-libs

Feel free to post your questions and ideas here.

Gitter Chat

We support Stack Overflow. Please add python-asyncio or aiohttp tag to your question there.

Indices and tables