MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / wait_all

Function wait_all

openhands/app_server/utils/async_utils.py:62–89  ·  view source on GitHub ↗

Shorthand for waiting for all the coroutines in the iterable given in parallel. Creates a task for each coroutine. Returns a list of results in the original order. If any single task raised an exception, this is raised. If multiple tasks raised exceptions, an AsyncException is raised con

(
    iterable: Iterable[Coroutine], timeout: int = GENERAL_TIMEOUT
)

Source from the content-addressed store, hash-verified

60
61
62async def wait_all(
63 iterable: Iterable[Coroutine], timeout: int = GENERAL_TIMEOUT
64) -> list:
65 """Shorthand for waiting for all the coroutines in the iterable given in parallel. Creates
66 a task for each coroutine.
67 Returns a list of results in the original order. If any single task raised an exception, this is raised.
68 If multiple tasks raised exceptions, an AsyncException is raised containing all exceptions.
69 """
70 tasks = [asyncio.create_task(c) for c in iterable]
71 if not tasks:
72 return []
73 _, pending = await asyncio.wait(tasks, timeout=timeout)
74 if pending:
75 for task in pending:
76 task.cancel()
77 raise asyncio.TimeoutError()
78 results = []
79 errors = []
80 for task in tasks:
81 try:
82 results.append(task.result())
83 except Exception as e:
84 errors.append(e)
85 if errors:
86 if len(errors) == 1:
87 raise errors[0]
88 raise AsyncException(errors)
89 return [task.result() for task in tasks]
90
91
92class AsyncException(Exception):

Callers 4

test_await_allFunction · 0.90
test_await_all_timeoutFunction · 0.90

Calls 1

AsyncExceptionClass · 0.85

Tested by 4

test_await_allFunction · 0.72
test_await_all_timeoutFunction · 0.72