When I enable asyncio debugging in Python 3.5, I get messages like this almost every second:
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
Here is a minimal code which reproduces this problem:
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
# ...
This doesn't print messages if sleep
delay is lesser than 1 second, but does if it is >= 1.
Is that expected behaviour? How can I avoid such messages?
I found that problem when working with Muffin framework.
You can set logging level for asyncio module, for example:
logging.getLogger('asyncio').setLevel(logging.WARNING) # Remove asyncio debug and info messages, but leave warnings.
BTW, read about logging names system generally:
The
name
is potentially a period-separated hierarchical value, likefoo.bar.baz
(though it could also be just plainfoo
, for example). Loggers that are further down in the hierarchical list are children of loggers higher up in the list. For example, given a logger with a name offoo
, loggers with names offoo.bar
,foo.bar.baz
, andfoo.bam
are all descendants offoo
. The logger name hierarchy is analogous to the Python package hierarchy, and identical to it if you organise your loggers on a per-module basis using the recommended constructionlogging.getLogger(__name__)
. That’s because in a module,__name__
is the module’s name in the Python package namespace.
Is that expected behaviour?
Yes, see https://github.com/python/cpython/blob/v3.6.1/Lib/asyncio/base_events.py#L1372
How can I avoid such messages?
Obviously, one way is to disable logging all-together. Or you could only print logging.DEBUG
level. Or you could write some sort of custom filter to filter out these messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With