python3.5垃圾邮件当我在Python 3.5使ASYNCIO调试,我得到的消息是这样,几乎每一秒钟:ASYNCIO与INFO
INFO:asyncio:poll 999.470 ms took 1001.159 ms: timeout
INFO:asyncio:poll 999.264 ms took 1001.092 ms: timeout
INFO:asyncio:poll 999.454 ms took 1001.059 ms: timeout
下面是一个最小的代码重新产生此问题:
import asyncio
import logging
logging.basicConfig(level=logging.DEBUG)
loop = asyncio.get_event_loop()
loop.set_debug(True)
async def f(delay):
for i in range(10):
await asyncio.sleep(delay)
loop.run_until_complete(f(0.5))
# (nothing printed)
loop.run_until_complete(f(1))
# INFO:asyncio:poll 999.470 ms took 1001.159 ms: timeout
# INFO:asyncio:poll 999.264 ms took 1001.092 ms: timeout
# INFO:asyncio:poll 999.454 ms took 1001.059 ms: timeout
# ...
loop.run_until_complete(f(2))
# INFO:asyncio:poll 1999.427 ms took 2001.112 ms: timeout
# INFO:asyncio:poll 1999.393 ms took 2001.088 ms: timeout
# INFO:asyncio:poll 1999.709 ms took 2001.758 ms: timeout
# ...
如果sleep
延迟是大于1秒更小的,但是,这不打印的消息,如果它是> = 1
那是预期的行为?我怎样才能避免这样的消息?
我Muffin framework工作时发现的问题。
看来,这个问题的根源在于'aiohttp' Web框架的gunicorn工人:https://github.com/KeepSafe/aiohttp/blob/master/aiohttp/worker.py#L97 - 它调用asyncio.sleep( 1.0)当服务器不忙时导致这个消息。 – MarSoft