5垃圾邮件中的Asyncio

5垃圾邮件中的Asyncio

当我在Python 3.5中启用异步调试时,几乎每秒都会收到类似这样的消息:

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时发现了这个问题。

最佳答案

您可以设置异步模块的日志记录级别,例如:

logging.getLogger('asyncio').setLevel(logging.WARNING)  # Remove asyncio debug and info messages, but leave warnings.

顺便说一句,read about日志名称系统通常:

关于python - 带有INFO的python3.5垃圾邮件中的Asyncio,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34501662/

10-10 10:28