Skip to content

Instantly share code, notes, and snippets.

@ksindi
Created July 14, 2017 03:17
Show Gist options
  • Save ksindi/da947e240f37804f48cca0d788b5f63e to your computer and use it in GitHub Desktop.
Save ksindi/da947e240f37804f48cca0d788b5f63e to your computer and use it in GitHub Desktop.
import asyncio
async def bar(i):
print('started', i)
await asyncio.sleep(1)
print('finished', i)
if i == 5:
raise ValueError("Foo")
return i
asyncio.set_event_loop(asyncio.new_event_loop())
loop = asyncio.get_event_loop()
tasks = asyncio.gather(*(bar(i) for i in range(10)), return_exceptions=True)
loop.run_until_complete(tasks)
results = tasks.result()
print(results)
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment