aioplus.awaitify¶
- aioplus.awaitify(func, /, *, executor=None)¶
Make a function asynchronous.
- Parameters:
func (Callable) – A callable to be wrapped for asynchronous execution.
executor (Executor, optional) – An optional
concurrent.futures.Executorto run the function in. IfNone, the default executor is used (usually a thread pool).
- Returns:
An asynchronous callable that, when awaited, runs the original function in the executor.
- Return type:
Callable
Examples
>>> import asyncio >>> >>> from aioplus import awaitify >>> >>> def func(num: int) -> None: >>> '''Print the number.''' >>> print(f'Num: {num}') >>> >>> async def main() -> None: >>> '''Run the program.''' >>> afunc = awaitify(func) >>> await afunc(num=2304) >>> >>> if __name__ == '__main__': >>> asyncio.run(main())
See also