Skip to content

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

@JPHutchins

Description

@JPHutchins

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions