使用带阻塞cod的asyncio

2024-10-04 01:26:47 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,我看了thisthis和{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),因此可能会有一些其他的复杂情况。)


Tags: self信息trueasyncmydefa1this