From 83ee7cade37b23f608823f2ed59a1c315b7e9478 Mon Sep 17 00:00:00 2001 From: Jason Gunthorpe Date: Fri, 25 Sep 2020 11:00:09 -0300 Subject: util: Use a different algorithm for asyncio_complete() The old version only worked on python > 3.7, this should work universally. Allow all the work in the gather list to finish naturally and just propogate any exceptions that might have been generated. Signed-off-by: Jason Gunthorpe --- cloud_mdir_sync/util.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cloud_mdir_sync/util.py b/cloud_mdir_sync/util.py index 836bf56..a35e5e4 100644 --- a/cloud_mdir_sync/util.py +++ b/cloud_mdir_sync/util.py @@ -75,9 +75,8 @@ async def asyncio_complete(*awo_list): """This is like asyncio.gather but it always ensures that the list of awaitable objects is completed upon return. For instance if an exception is thrown then all the awaitables are canceled""" - g = asyncio.gather(*awo_list) - try: - return await g - finally: - g.cancel() - await asyncio.gather(*awo_list, return_exceptions=True) + res = await asyncio.gather(*awo_list, return_exceptions=True) + for I in res: + if isinstance(I, Exception): + raise I + return res -- cgit v1.2.3