Skip to content

vllm.utils.async_utils

Contains helpers related to asynchronous code.

This is similar in concept to the asyncio module.

Functions:

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.

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.

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.