0

I need to create an asyncio implementation of an existent class, but I have to preserve the syncronous interface. In other words I have to put some wrappers around the coroutines to make them callable like normal blocking functions. I tried to do something like this:

class MyClass:
    def __init__(self, loop, ...):
        self._loop = loop
        ...
    async def cor(...):
        ...
    def method(...):
        t = self._loop.create_task(self.cor(...))
        while not t.done(): time.sleep(1)
        return t.result()

However it doesn't work. The while hangs forever. I think the sleep call is blocking the event loop. I'm new to asyncio programming. How is this situation supposed to be handled?

Jean
  • 11
  • 1

0 Answers0