Skip to main content

async-executor

PyPI - Version

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.

Metadata

Release files for async-executor 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-executor 0.1.2
File Size Uploaded
async_executor-0.1.2.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-executor 0.1.2
File Interpreter ABI Platform
async_executor-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.0 kB

Release files / async_executor-0.1.2.tar.gz

Download URL async_executor-0.1.2.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
910e74dd7aaaa2a39f3e3fc91e3f87a01d23bea650fbf431746d2961f928d482
BLAKE2b-256 checksum
How to use checksums
59bc6bd2b0133f30854235748c7175c598c38e6b18aa3fb70d683dcbea09eda0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

Release files / async_executor-0.1.2-py3-none-any.whl

Download URL async_executor-0.1.2-py3-none-any.whl
Size 3.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44596587fae296ce12cfd25127ae91dadeb2f10e81769a7326ac7201b2d24e20
BLAKE2b-256 checksum
How to use checksums
98c478e168f6847d46e4f86a109ec88ba765fcb9d793c5c1968a44e7b71fc239
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page