我对 celery 的记录器有疑问。我有一个渲染帧的函数。我记录了我生成的子进程的输出,但似乎只有每个工作人员从队列中挑选的第一个作业被写入。队列中的所有后续任务都不会生成日志文件。我也尝试过使用 python 自己的日志记录,并且发生了同样的问题。是否有我可能缺少的配置?
@task(queue='rndr')
def rndr(params):
path = get_logger_path(params)
logger = rndr.get_logger(logfile=path)
return render(params, logger)
我以这种方式定义我的任务,因为我的重试记录器的定义不同,即 rndr_retry.get_logger...
我的 celeryconfig 如下所示:
BROKER_HOST = "xxx.xxx.xxx.xxx"
BROKER_PORT = 5672
BROKER_USER = "xxxx"
BROKER_PASSWORD = "xxxx"
CELERY_RESULT_BACKEND = 'amqp'
CELERY_DISABLE_RATE_LIMITS = True
CELERY_ACKS_LATE = True
CELERY_IMPORTS = ['lib.tasks.concatenate', 'lib.tasks.encode', 'lib.tasks.render', 'lib.tasks.still_image', 'lib.tasks.retry']
CELERY_ROUTES = {'lib.tasks.encode':{'queue': 'encode'},
'lib.tasks.concatenate':{'queue': 'encode'},
'lib.tasks.still_image':{'queue': 'encode'},
'lib.tasks.render':{'queue':'rndr'},
'lib.tasks.retry':{'queue': 'retry'}
}
希望有人能解释为什么只有队列中的第一个任务才会写......
先感谢您。
更新:根据要求,这里是渲染方法的部分版本,没有所有细节......
def render(params, logger):
#load params to local values
try:
#create subprocess
output = child_proc.communicate()[0]
logger.info('output')
logger.info(output)
ret = child_proc.wait()
if ret not in [0,1]:
raise Exception('subprocess failed')
except Exception, exc:
logger.info(' '.join(str(x) for x in exc.args))
#mark as failed...
return
return
我应该补充一点,该文件不仅不会在后续任务中被写入,它甚至不会创建日志文件......