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