0

I am using this library https://github.com/liamw9534/pyconnman to control connman via python/dbus. The problem is that all the other modules that I'm using are usign async api.

How to convert this module to use async function calls?

In general, if I want a library to be available both in sync and async "way", what is the recommended pattern to use?

like

class myExampleConnectorClass:
    def

class myExampleAsyncConnectorClass:
    async def my_method(self):
        pass

class myCustomObj(myExampleConnectorClass):
    def my_method(self):
        return super().my_method()

How I can define the same derived class and decide when I instantiate it if I want the async or sync version?

Thanks Nick

Dschoni
  • 3,714
  • 6
  • 45
  • 80
  • [How to write your own async coroutine function](https://stackoverflow.com/q/58270147/3702377) – Benyamin Jafari Dec 11 '19 at 10:20
  • If the mentioned library is not async/awaitable you cannot run it as asynchronous, you should run it sequentially. – Benyamin Jafari Dec 11 '19 at 10:25
  • Maybe I didn't explain myself. i have a libray not designed to be used with asyncio (is using glib eventloop I think) and I want to encapsulate it and use it with a library that is using async call. Can I encapsulate the main gio loop inside an asyncio coroutine and encapsulate the function call in some way? – Nicola Lunghi Jan 28 '20 at 11:53
  • I don't know correctly. However, there is a library which is called `ray`, it could convert an unawaitable method to add an asyncio loop. [Here is an example](https://ray.readthedocs.io/en/latest/async_api.html) – Benyamin Jafari Jan 28 '20 at 12:02

0 Answers0