Asyncio background tasks

buildstatus coverage

Asyncio background tasks

Asyncio background tasks in Python 3.7 and later.

Run CPU intensive long running tasks without blocking the asyncio loop, implemented as a lightweight asyncio layer on top of the multiprocessing module.

Project homepage:



pip install asyncbg


There are more examples in the examples folder.


Call work(a, b) in another process. The script output is Result: 9.

import asyncio
import asyncbg

def work(a, b):
    return a + b

async def main():
    result = await, 4, 5)
    print(f'Result: {result}')

Process pool

Create a process pool with two workers, and call work() three times in it (up to two callbacks called in parallel).

import asyncio
import asyncbg

def work():

async def main():
    pool = asyncbg.ProcessPoolExecutor(max_workers=2)
    await asyncio.gather(,

Functions and classes, *args, **kwargs)[source]

Coroutine calling given callback with given arguments in another process.

Returns the value returned by the callback, or raises the exceptions raised by the callback.

Callback positional and keyword arguments can not be used for output, as the multiprocessing module does not support that.

Call work() in a worker process:

>>> def work():
>>>     pass
class asyncbg.ProcessPoolExecutor(max_workers=None, mp_context=None, initializer=None, initargs=())[source]

Same as concurrent.futures.ProcessPoolExecutor, but with the call() method added.