我想沿着以下使用@property装饰器与@ asyncio.coroutine没有做可能的产量?
Foo(object):
@property
@asyncio.coroutine
def bar(self):
# This will need to run some blocking code via loop.run_in_executor()
return 'bar'
线一类,然后我想,而不必一个yield from
# In a loop...
foo = Foo()
foo.bar #This will return a generator object, but I want it to return 'bar'.
yield from foo.bar #This will return 'bar', but I don't want to do the yield from.
访问属性是这样的事情可能吗?
运行协程生成器的唯一方法是使用'yield from',由此调用协程有效地驱动它,否则使用诸如asyncio.async之类的东西来驱动它。否则,它只是一个“惰性”的发电机对象,根据你的观察。 – shongololo
@shongololo不妨做出答案。 – dano