Skip to content
Jobs scheduler for managing background task (asyncio)
Branch: master
Clone or download
pyup-bot and asvetlov Scheduled weekly dependency update for week 09 (#91)
* Update pytest from 4.0.0 to 4.3.0

* Update pytest-cov from 2.6.0 to 2.6.1

* Update flake8 from 3.6.0 to 3.7.7

* Update isort from 4.3.4 to 4.3.10

* Update wheel from 0.32.3 to 0.33.1

* Update flit from 1.2.1 to 1.3

* Update flit from 1.2.1 to 1.3

* Update sphinx from 1.8.3 to 1.8.4
Latest commit 232822c Mar 5, 2019


aiojobs Documentation Status Chat on Gitter

Jobs scheduler for managing background task (asyncio)

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()


Integration with aiohttp.web

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

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()

For more information read documentation:

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.

Author and License

The aiojobs package is written by Andrew Svetlov.

It's Apache 2 licensed and freely available.

You can’t perform that action at this time.