Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plans to use async libs instead of threads? #1199

Open
JPHutchins opened this issue Oct 23, 2024 · 0 comments
Open

Any plans to use async libs instead of threads? #1199

JPHutchins opened this issue Oct 23, 2024 · 0 comments

Comments

@JPHutchins
Copy link

Is your feature request related to a problem? Please describe.

It seems like sync libs are being used and tossed onto OS threads, are there any plans to use asyncio libs? e.g. aiomqtt instead of paho mqtt https://github.com/empicano/aiomqtt

def emulate_async(fn):
"""Returns a coroutine function that calls a given function with emulated asynchronous
behavior via use of multithreading.
Can be applied as a decorator.
:param fn: The sync function to be run in async.
:returns: A coroutine function that will call the given sync function.
"""
@functools.wraps(fn)
async def async_fn_wrapper(*args, **kwargs):
loop = asyncio.get_running_loop()
# Run fn in default ThreadPoolExecutor (CPU * 5 threads)
return await loop.run_in_executor(None, functools.partial(fn, *args, **kwargs))
return async_fn_wrapper

Describe the solution you'd like
Usage of asyncio.

Describe alternatives you've considered
If I had to I suppose I would just implement the calls manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant