Asyncio background tasks.
Project description
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: https://github.com/eerimoq/asyncbg
Documentation: https://asyncbg.readthedocs.org/en/latest
Installation
pip install asyncbg
Examples
There are more examples in the examples folder.
Call
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 asyncbg.call(work, 4, 5)
print(f'Result: {result}')
asyncio.run(main())
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():
pass
async def main():
pool = asyncbg.ProcessPoolExecutor(max_workers=2)
await asyncio.gather(pool.call(work),
pool.call(work),
pool.call(work))
asyncio.run(main())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asyncbg-0.6.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for asyncbg-0.6.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8de9ffd0828a580d986c62ce45e2a22688714820c82c39ff55167c7ad50fea5d |
|
MD5 | f0386916526dd0addd4b398384640506 |
|
BLAKE2b-256 | c090e12a20e1a8465907e1e771d48e59b1189d10d356046fdc2e806dc72a42f1 |