From aa2bf7875727eb01cfd234adb76108579717785c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 30 Dec 2019 01:52:44 +0100 Subject: [PATCH] Document a function --- royalnet/utils/asyncify.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/royalnet/utils/asyncify.py b/royalnet/utils/asyncify.py index 08ca349b..e4a7522f 100644 --- a/royalnet/utils/asyncify.py +++ b/royalnet/utils/asyncify.py @@ -4,10 +4,16 @@ import typing async def asyncify(function: typing.Callable, *args, loop: typing.Optional[asyncio.AbstractEventLoop] = None, **kwargs): - """Asyncronously run the function in a different thread or process, preventing it from blocking the event loop. + """Asyncronously run the function in a executor, allowing it to run asyncronously. + + Args: + function: The function to call. + args: The arguments to pass to the function. + kwargs: The keyword arguments to pass to the function. + loop: The loop to run the function in. If :const:`None`, run it in in the current event loop. Warning: - If the function has side effects, it may behave strangely.""" + The called function must be thread-safe!""" if not loop: loop = asyncio.get_event_loop() return await loop.run_in_executor(None, functools.partial(function, *args, **kwargs))