我想沿着以下使用@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