Timeout for python coroutines
问题 How can I make a coroutine stop with timeout? I don't understand why asyncio.wait_for() doesn't work for me. I have such piece of code (planning to make my implementation of telnet client): def expect(self, pattern, timeout=20): if type(pattern) == str: pattern = pattern.encode('ascii', 'ignore') return self.loop.run_until_complete(asyncio.wait_for(self.asyncxpect(pattern), timeout)) async def asyncxpect(self, pattern): #receives data in a cumulative way until match is found regexp = re