Skip to content Skip to sidebar Skip to footer

Using @property Decorator With @asyncio.coroutine Without Doing Yield From Possible?

I want a class along the lines of the following Foo(object): @property @asyncio.coroutine def bar(self): # This will need to run some blocking code via loop.run

Solution 1:

The way to run a coroutine generator is to use yield from (await in Python 3.5) from another coroutine. The yield from (await) is what allows one coroutine to drive another coroutine, which normally means that you have chains of linked coroutines that are ultimately driven by the event loop.

Another option is to use a Task-like wrapper like asyncio.async (ensure_future() in Python 3.5) to drive the coroutine.

Without one of the above, it's just an inert generator object (or coroutine, in Python 3.5) per your observations.

Post a Comment for "Using @property Decorator With @asyncio.coroutine Without Doing Yield From Possible?"