简体   繁体   English

在芹菜任务中不打印

[英]not printing inside celery task

In my celery I tried printing inside a task, but I cant seem to output the data even in console. 在我的芹菜中,我尝试在任务中进行打印,但是即使在控制台中,我似乎也无法输出数据。

Here is my structure: 这是我的结构:

/app.py
@app.route('//create', methods = ['POST'])
def create_file():
request.form .......
callback = build_file.s(name, address)
header = [ send_param.s( id, key ) for key in request_api.keys() ]
result = chord(header)(callback)

@celery.task(name='app.send_param', routing_key='send_param', queue='send_param', retry=False, bind=True)
def send_param(seld, id, key):
    //do something
    print 'NOT WORKING'

@celery.task(name='app.build_file', routing_key='send_param', queue='send_param', retry=False, bind=True)
def build_file(seld, name, address):
    //do something
    print 'NOT WORKING'

When printing within my create_file function it does print, but within my tasks it doesnt. 在我的create_file函数中打印时,它会打印,但在我的任务中却不会。

The most straightforward solution will be to: 最直接的解决方案是:

1) Configure a Logger instance which will capture all output from logger.info() (and other log levels) and put it into a local file or just stdout 1)配置一个Logger实例,该实例将捕获logger.info() (和其他日志级别)的所有输出,并将其放入本地文件或仅stdoutstdout

2) While configuring, set 2)在配置时,设置

app.conf.update(CELERYD_HIJACK_ROOT_LOGGER=False)

to prevent Celery from removing any previously configured Loggers (more info: http://docs.celeryproject.org/en/latest/configuration.html#logging ). 以防止Celery删除任何以前配置的Logger(更多信息: http : //docs.celeryproject.org/en/latest/configuration.html#logging )。


Another option could be using the Siglans: http://docs.celeryproject.org/en/latest/userguide/signals.html 另一种选择是使用Siglans: http ://docs.celeryproject.org/en/latest/userguide/signals.html

but it is a little bit more involved and probably an overkill in your situation. 但这会涉及到更多情况,可能对您造成不利影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM