/asyncio_gather_exception_true.py Secret
Created
October 4, 2020 16:35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
async def some_async_task(): | |
await asyncio.sleep(4) | |
return "result from some_async_task()" | |
async def some_async_task2(): | |
await asyncio.sleep(2) | |
raise "Some exception" | |
async def main(): | |
result = await asyncio.gather(some_async_task(), some_async_task2(), return_exceptions=True) | |
print(result) | |
asyncio.run(main()) | |
"""Output: | |
['result from some_async_task()', TypeError('exceptions must derive from BaseException')] | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment