vllm.utils.async_utils ¶
Contains helpers related to asynchronous code.
This is similar in concept to the asyncio module.
Functions:
-
collect_from_async_generator–Collect all items from an async generator into a list.
-
make_async–Take a blocking function, and run it on in an executor thread.
-
make_async_with_semaphore–Take a blocking function, and run it on in an executor thread.
-
merge_async_iterators–Merge multiple asynchronous iterators into a single iterator.
collect_from_async_generator(iterator) async ¶
Collect all items from an async generator into a list.
make_async(func, executor=None) ¶
Take a blocking function, and run it on in an executor thread.
This function prevents the blocking function from blocking the asyncio event loop. The code in this function needs to be thread safe.
Source code in vllm/utils/async_utils.py
make_async_with_semaphore(func, executor) ¶
Take a blocking function, and run it on in an executor thread.
This function prevents the blocking function from blocking the asyncio event loop. The code in this function needs to be thread safe.
The function is wrapped in a semaphore to limit the number of concurrent executions making it easier to cancel tasks before they start.
Source code in vllm/utils/async_utils.py
merge_async_iterators(*iterators) async ¶
Merge multiple asynchronous iterators into a single iterator.
This method handle the case where some iterators finish before others. When it yields, it yields a tuple (i, item) where i is the index of the iterator that yields the item.