Async

Helper module to add some utils to Python’s asyncio.

cli2.asyncio.async_iter(obj)[source]

Check if an object is an async iterable.

async cli2.asyncio.async_resolve(result, output=False)[source]

Recursively resolve awaitables and async iterables.

Parameters:
  • result – The awaitable or async iterable to resolve

  • output – If True, print results as they are resolved. If False, collect results.

Returns:

The resolved value(s). If output is True, returns None. If output is False, returns a list of resolved values from async iterables.

async cli2.asyncio.files_read(*paths, num_workers=None, mode='r')[source]

Read a list of files asynchronously with anyio.

Parameters:
  • paths – File paths to read.

  • num_workers – Number of workers, cpucount*2 by default.

Returns:

Dict of path=content