Is it good to add an arg "use_thread" in asyncify
function?
#168
-
First Check
Commit to Help
Example CodeHi here.
If I didn't see the second paragraph above, I would believe that any sync function could be asyncified by async def wrapper(
*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs
) -> T_Retval:
partial_f = functools.partial(function, *args, **kwargs)
return await anyio.to_thread.run_sync(
partial_f, cancellable=cancellable, limiter=limiter
) It uses DescriptionIf the sync function is IO-intensive, Operating SystemLinux Operating System DetailsNo response asyncer Version0.0.7 Python Version3.10.12 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, currently docs don't cover the topic of performance optimization. But the following statement is not correct
It will work - your sync function is CPU-intensive will not block the event loop and this is what It might be a good idea to add a section in docs describing use cases that are better to solve with other approaches |
Beta Was this translation helpful? Give feedback.
Yes, currently docs don't cover the topic of performance optimization.
But the following statement is not correct
It will work - your sync function is CPU-intensive will not block the event loop and this is what
asyncify
is intended to solve.It might be a good idea to add a section in docs describing use cases that are better to solve with other approaches