Collection of utilities to write safe asyncio code.
Project description
asynchrony
Python asyncio framework for writing safe and fast concurrent code.
Features:
- Type annotated and type safe
- Makes it easy to work with cancellation, errors, and scheduling.
- Well tested and well documented.
- Zero dependency.
- Based on real world experience and pain.
Installation and usage
python3 -m pip install asynchrony
A simple example of starting concurrent tasks for all URLs (maximum 100 tasks at the same time) and waiting for all of them to finish:
from asynchrony import Tasks
async def download_page(url: str) -> bytes:
...
urls = [...]
tasks = Tasks[bytes](timeout=10, max_concurrency=100)
tasks.map(urls, download_page)
try:
pages = await tasks
except Exception:
failed = sum(t.failed for t in tasks)
print(f'{failed} tasks failed')
cancelled = sum(t.cancelled for t in tasks)
print(f'{cancelled} tasks cancelled')
else:
print(f'finished {len(tasks)} tasks')
See tutorial for runnable usage examples.
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
asynchrony-0.2.0.tar.gz
(11.9 kB
view details)
Built Distribution
File details
Details for the file asynchrony-0.2.0.tar.gz
.
File metadata
- Download URL: asynchrony-0.2.0.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9589dca3257843294a9965fff2de41a45fd4356e94aeae8587e453b67e23260e |
|
MD5 | 288ba9be19ef8329e8c96789737b429b |
|
BLAKE2b-256 | 28f74c9dc1029e4ca6bd3c1893293af653c339ccb8ecee79a73f70416f10e777 |
File details
Details for the file asynchrony-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: asynchrony-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1823458b27e9eecdd8dd034ae1010fdaa9e51fd44098a417cd7da10b747d4c8 |
|
MD5 | d8444e52c6d96af1210f430580b076f3 |
|
BLAKE2b-256 | e22c937b315a4d3600bc7d9c69b6ec83a0c1b04a67d57fed468d308199190233 |