2015-12-28 61 views
7

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工作時發現的問題。

+0

看來,這個問題的根源在於'aiohttp' Web框架的gunicorn工人:https://github.com/KeepSafe/aiohttp/blob/master/aiohttp/worker.py#L97 - 它調用asyncio.sleep( 1.0)當服務器不忙時導致這個消息。 – MarSoft

回答

1

可以設置日誌記錄級別ASYNCIO模塊,例如:

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

順便說一句,read about測井名系統一般:

name是一個潛在的時間段隔開的分層值,像 foo.bar.baz(雖然它也可能只是簡單的foo,例如)。 層次列表中進一步向下的記錄器是列表中較高位置的 記錄器的子項。例如,給定具有名稱 的foo的記錄器,名稱爲foo.bar,foo.bar.bazfoo.bam的記錄器是 的所有後代foo。如果您使用推薦的建設 logging.getLogger(__name__)組織在每個模塊爲基礎的 記錄器記錄器名稱層次是類似於 Python包的層次結構,並等同於它。這是因爲在模塊中,__name__是 模塊在Python包名稱空間中的名稱。