12

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.

1

2 Answers 2

8

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, like foo.bar.baz (though it could also be just plain foo, 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 of foo, loggers with names of foo.bar, foo.bar.baz, and foo.bam are all descendants of foo. 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 construction logging.getLogger(__name__). That’s because in a module, __name__ is the module’s name in the Python package namespace.

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.