Useful utilities for working with asyncio.
Project description
asyncio_tools
Useful utilities for working with asyncio - currently in alpha.
gather
Provides a convenient wrapper around asyncio.gather
.
from asyncio_tools import gather, CompoundException
async def good():
return 'OK'
async def bad():
raise ValueError()
async def main():
response = await gather(
good(),
bad(),
good()
)
# Check if a particular exception was raised.
ValueError in response.exception_types
# >>> True
# To get all exceptions:
print(response.exceptions)
# >>> [ValueError()]
# To get all instances of a particular exception:
response.exceptions_of_type(ValueError)
# >>> [ValueError()]
# To get the number of exceptions:
print(response.exception_count)
# >>> 1
# You can still access all of the results:
print(response.all)
# >>> ['OK', ValueError(), 'OK']
# And can access all successes (i.e. non-exceptions):
print(response.successes)
# >>> ['OK', 'OK']
# To get the number of successes:
print(response.success_count)
# >>> 2
try:
# To combines all of the exceptions into a single one, which merges the
# messages.
raise response.compound_exception()
except CompoundException as compound_exception:
print("Caught it")
if ValueError in compound_exception.exception_types:
print("Caught a ValueError")
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
asyncio_tools-0.1.0.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for asyncio_tools-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4de8243b05fb1e32e0c59b6955e9f57cf7e31f0ca38a5e7da58f81edd0916d13 |
|
MD5 | f9d48a3eb1e5393096a05e16387a24e2 |
|
BLAKE2b-256 | 48b00e123bde10c411c588b42760cf021dee2dfa2f5a4728d39204993d1b40a9 |