首先,我看了this、this和{a1},虽然第一个有一些有用的信息,但它在这里并不相关,因为我试图迭代值。在
下面是一个我想做的事情的例子:
class BlockingIter:
def __iter__(self):
while True:
yield input()
async def coroutine():
my_iter = BlockingIter()
#Magic thing here
async for i in my_iter:
await do_stuff_with(i)
我该怎么做?在
(注意,BlockingIter
实际上是我正在使用的一个库(chatexchange),因此可能会有一些其他的复杂情况。)
正如@vaultah在docs中所说和解释的,
awaiting
,executor
(await loop.run_in_executor(None, next, iter_messages)
)可能就是你想要的。在相关问题 更多 >
编程相关推荐