ironic.common.async_utils module¶
Helpers for running asynchronous code from synchronous callers.
- async ironic.common.async_utils.gather_with_keys(items, limit=None, timeout=None)[source]¶
Run awaitables concurrently, keeping each result with its key.
Exceptions are returned alongside their key instead of being raised, so that one failing awaitable does not discard the results of the others. It is up to the caller to tell results and exceptions apart.
- Parameters:
items – an iterable of (key, awaitable) pairs. A key can be any object identifying the awaitable to the caller.
limit – the greatest number of awaitables allowed to run at once. Every awaitable is still scheduled up front, but one only starts running once fewer than
limitothers are in flight, which bounds the resources they hold open between them. None, or any value below 1, places no bound.timeout – seconds to allow for all of the awaitables together. Whatever has finished by then is returned; the rest are cancelled and come back as
CancelledErroragainst their own key, so one awaitable that never finishes costs its own result rather than everybody’s. None waits indefinitely.
- Returns:
a list of (key, result) tuples in the order of
items, where a result is either the value the awaitable produced or the exception it raised. Note that a cancelled awaitable yieldsCancelledError, which is a BaseException and not an Exception, so callers testing for failures must take that into account.