2016-12-05 27 views
0

我正在嘗試使用app.conf.humanize(with_defaults=False)打印出芹菜的配置,下面是user guide中的示例。但是在使用with_defaults=False時,我總是會得到一個空字符串,我知道配置更改已生效,因爲我可以使用.humanize(with_defaults=True)來查看更改。芹菜app.conf.humanize的默認值是什麼(with_defaults = False)?

我猜想用app.conf.config_from_object('myconfig')添加配置會將配置設置加載爲「默認值」,因此有沒有一種方法可以以非默認方式在模塊myconfig加載配置?

這是我的源代碼:

#myconfig.py 
worker_redirect_stdouts_level='INFO' 
imports = ('tasks',) 

#tasks.py 
from celery import Celery 

app = Celery() 
app.config_from_object('myconfig')  
print "config: %s" % app.conf.humanize(with_defaults=False) 

@app.task 
def debug(*args, **kwargs): 
    print "debug task args : %r" % (args,) 
    print "debug task kwargs: %r" % (kwargs,) 

我使用env PYTHONPATH=. celery worker --loglevel=INFO開始芹菜,它打印config:(如果我更改爲with_defaults=True我得到預期的全輸出)。

+0

我提起[錯誤報告(https://github.com/celery/celery/issues/3652),因爲它看起來'humanize()'在訪問conf的'app.conf ['worker_redirect_stdouts_level']' – ecerulm

回答

0

加載了config_from_object()config_from_envvar()的配置不被視爲默認設置。

觀察到的行爲,是由於預期由this commit響應固定到我的bug report芹菜所以未來版本的bug,會工作。

from celery import Celery 
app = Celery 
app.config_from_object('myconfig') 
app.conf.humanize() # returns only settings directly set by 'myconfig' omitting defaults 

其中myconfigPYTHONPATH一個python模塊:

#myconfig.py 
worker_redirect_stdouts_level='DEBUG'