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.
Alternatively run tasks in other threads.
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():
with asyncbg.ProcessPoolExecutor(max_workers=2) as pool:
await asyncio.gather(pool.call(work),
pool.call(work),
pool.call(work))
asyncio.run(main())
Call thread
Call work(a, b) in another thread. The script output is Result: 9.
import asyncio
import asyncbg
def work(a, b):
return a + b
async def main():
result = await asyncbg.call_thread(work, 4, 5)
print(f'Result: {result}')
asyncio.run(main())
Thread pool
Create a thread 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():
with asyncbg.ThreadPoolExecutor(max_workers=2) as pool:
await asyncio.gather(pool.call(work),
pool.call(work),
pool.call(work))
asyncio.run(main())
Metadata
Release files for asyncbg 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asyncbg-0.12.0.tar.gz | 3.9 kB | Without provenance | Details for asyncbg-0.12.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncbg-0.12.0-py3-none-any.whl | Python 3 | none | any | Details for asyncbg-0.12.0-py3-none-any.whl |
Total release size: 7.4 kB
Release files / asyncbg-0.12.0.tar.gz
| Download URL | asyncbg-0.12.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8dc556953f829e4b2c31307cd7480273ef88322468dc1ef0c7d1c292bf056fc
|
|
BLAKE2b-256 checksum How to use checksums |
fec4905e83237e0357fc86637a2099adddb75d34d4780166e82088e49e1295f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / asyncbg-0.12.0-py3-none-any.whl
| Download URL | asyncbg-0.12.0-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12bc0046830a52b50a67a98a927c1dd36c2aea978baf0cda2d556eae39cfcb39
|
|
BLAKE2b-256 checksum How to use checksums |
8935dcac913f52ca4da452f3c15b2095da2745deff832c568eb9fc06305f94d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for asyncbg 0.12.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.