async-executor
Async execution pool
Examples
Limit the number of concurrently running awaitables
import asyncio
import time
import async_executor
async def sleep_and_print(i):
print(f'{i} {int(time.time())} - before sleep')
await asyncio.sleep(1)
print(f'{i} {int(time.time())} - after sleep')
async def main():
# limit to a maximum of two concurrent executions
executor = async_executor.AsyncExecutor(max_concurrent=2)
# awaitables are only queued here - nothing is run
for i in range(5):
executor.submit(sleep_and_print, i)
# awaitables begin executing
async for task in executor:
task.result()
asyncio.run(main())
This shows that only a maximum of two executions are allowed to run concurrently.
$ python examples/example_1.py
0 1670613515 - before sleep
1 1670613515 - before sleep
0 1670613516 - after sleep
1 1670613516 - after sleep
2 1670613516 - before sleep
3 1670613516 - before sleep
2 1670613517 - after sleep
3 1670613517 - after sleep
4 1670613517 - before sleep
4 1670613518 - after sleep
Installation
pip install async-executor
License
async-executor is distributed under the terms of the MIT license.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async_executor-0.1.2.tar.gz
(2.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async_executor-0.1.2.tar.gz.
File metadata
- Download URL: async_executor-0.1.2.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
910e74dd7aaaa2a39f3e3fc91e3f87a01d23bea650fbf431746d2961f928d482
|
|
| MD5 |
0794fd3f961ef833472e18184b2f4f8c
|
|
| BLAKE2b-256 |
59bc6bd2b0133f30854235748c7175c598c38e6b18aa3fb70d683dcbea09eda0
|
File details
Details for the file async_executor-0.1.2-py3-none-any.whl.
File metadata
- Download URL: async_executor-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44596587fae296ce12cfd25127ae91dadeb2f10e81769a7326ac7201b2d24e20
|
|
| MD5 |
a53fa63c0fd3ec9049f5be8c25d63e48
|
|
| BLAKE2b-256 |
98c478e168f6847d46e4f86a109ec88ba765fcb9d793c5c1968a44e7b71fc239
|