asyncio-taskpool
Dynamically manage pools of asyncio tasks
Full documentation available at RtD.
Contents
Summary
A task pool is an object with a simple interface for aggregating and dynamically managing asynchronous tasks.
With an interface that is intentionally similar to the multiprocessing.Pool class from the standard library, the TaskPool provides you such methods as apply, map, and starmap to execute coroutines concurrently as asyncio.Task objects. There is no limitation imposed on what kind of tasks can be run or in what combination, when new ones can be added, or when they can be cancelled.
For a more streamlined use-case, the SimpleTaskPool provides an even more intuitive and simple interface at the cost of flexibility.
If you need control over a task pool at runtime, you can launch an asynchronous ControlServer to be able to interface with the pool from an outside process or via a network, and stop/start tasks within the pool as you wish.
Usage
Generally speaking, a task is added to a pool by providing it with a coroutine function reference as well as the arguments for that function. Here is what that could look like in the most simplified form:
from asyncio_taskpool import SimpleTaskPool
...
async def work(_foo, _bar): ...
async def main():
pool = SimpleTaskPool(work, args=('xyz', 420))
pool.start(5)
...
pool.stop(3)
...
await pool.gather_and_close()
Since one of the main goals of asyncio-taskpool is to be able to start/stop tasks dynamically or "on-the-fly", most of the associated methods are non-blocking most of the time. A notable exception is the gather_and_close method for awaiting the return of all tasks in the pool. (It is essentially a glorified wrapper around the asyncio.gather function.)
For working and fully documented demo scripts see USAGE.md.
Installation
pip install asyncio-taskpool
Dependencies
Python Version 3.8+, tested on Linux
Testing
Install coverage with pip, then execute the cov.sh shell script to run all unit tests and save the coverage report.
License
asyncio-taskpool is licensed under the GNU LGPL version 3.0 specifically.
The full license texts for the GNU GPLv3.0 and the GNU LGPLv3.0 are included in this repository. If not, see https://www.gnu.org/licenses/.
© 2023 Daniil Fajnberg
Metadata
Release files for asyncio-taskpool 1.2.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 |
|---|---|---|---|---|
| asyncio-taskpool-1.2.0.tar.gz | 82.3 kB | Without provenance | Details for asyncio-taskpool-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asyncio_taskpool-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for asyncio_taskpool-1.2.0-py3-none-any.whl |
Total release size: 134.3 kB
Release files / asyncio-taskpool-1.2.0.tar.gz
| Download URL | asyncio-taskpool-1.2.0.tar.gz |
|---|---|
| Size | 82.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc39d3cccadce11930945e0ff1510715e7b1566780831e4a37949620e8da7248
|
|
BLAKE2b-256 checksum How to use checksums |
cc47d140836d5df22c8ad33d297b9c44c3f737f452a04cb3a784109860fab7c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.6
|
Release files / asyncio_taskpool-1.2.0-py3-none-any.whl
| Download URL | asyncio_taskpool-1.2.0-py3-none-any.whl |
|---|---|
| Size | 52.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8b294c91a3b8a157cbce7c52af5f28be3fdcf30843e30c484db4b9b198793e0
|
|
BLAKE2b-256 checksum How to use checksums |
223247861b1185920430226d4c44548d4283c69eb40c708c409f9499f790afca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.6
|
Security for asyncio-taskpool 1.2.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.