我是Asynchronous Python的新手。我研究异步迭代器的行为。 我做了pep492所写的一切。但得到它运行时错误:任务得到了不好的收益:1 。帮助请理解我做错了什么。在这个网站上,我读到了这个错误但是什么都不懂
class Awaitable:
def __await__(self):
i = 1
while i < 3:
yield i
print("yield {}".format(i))
i +=1
return i
class AsyncIterator:
def __aiter__(self):
return self
async def __anext__(self):
try:
value = await Awaitable()
except StopIteration:
raise StopAsyncIteration
return value
i = AsyncIterator().__aiter__()
async def coro():
while True:
try:
row = await i.__anext__()
print(row)
except StopAsyncIteration:
break
else:
print(row)
event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(coro())
.............................................................
File "C:\Users\mykola\Downloads\async_await.py", line 342, in __await__
yield i
RuntimeError: Task got bad yield: 1