I've got a function f() that makes an API call and I want to call it multiple times asynchronously. I use the asyncio lib like that:
async def main():
loop = asyncio.get_event_loop()
futures = [loop.run_in_executor(None, f) for i in range(10)]
await asyncio.gather(*futures)
return futures
result = asyncio.get_event_loop().run_until_complete(main())
The problem is that sometimes f() raises an Exception and I'm not sure how to handle it. The doc says that Futures can contain an Exception, but that's not the case here, error is raised and program crashes.
How do I achieve that ? I think I could write a wrapper for f() and try: catch: the Exception, but that seems ugly if the feature is provided by the lib.
Thanks in advance for help,