dee*_*eko 0 python logging celery
我对 celery 的记录器有问题。我有一个渲染帧的函数。我记录了我生成的子进程的输出,但似乎只有每个工作人员从队列中挑选的第一个作业被写入。队列中的所有后续任务都不会生成日志文件。我也尝试过使用 python 自己的日志记录,但发生了同样的问题。是否有我可能缺少的配置?
@task(queue='rndr')
def rndr(params):
path = get_logger_path(params)
logger = rndr.get_logger(logfile=path)
return render(params, logger)
Run Code Online (Sandbox Code Playgroud)
我以这种方式定义我的任务,因为我的重试记录器的定义不同,即 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'}
}
Run Code Online (Sandbox Code Playgroud)
希望有人能解释为什么只有队列中的第一个任务会写...
先感谢您。
更新:根据要求,这里是渲染方法的部分版本,没有所有细节......
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
Run Code Online (Sandbox Code Playgroud)
我应该补充一点,该文件不仅不会在后续任务中写入,它甚至不会创建日志文件....
经过一些试验,我注意到没有创建传递的日志文件。在将文件传递给 get_logger() 之前,我添加了一个方法来确保文件存在。仍然没有运气。由于我的大多数任务都运行子进程,因此我决定采用更简单的方法并打开一个文件对象并将其传递给 stdout 和 stderr 中的子进程调用,并在适当的情况下关闭文件对象。无论我运行多少任务,这似乎都有效。我应该注意每个任务都写入一个唯一的文件。
Anyhoo,我想我会写信给芹菜开发人员并将其标记为错误。我在开发论坛的某个地方读到过芹菜记录器需要一些爱。
干杯。
更新:
在与 celery 的开发人员交谈后,得出的结论是记录器不应该以这种方式使用。为任务启动日志记录实例,但不会记录重复的任务。我最终只是写了一个文件来规避日志模块的问题。因为每个渲染任务都使用一个唯一的文件,所以不会导致任何冲突。
| 归档时间: |
|
| 查看次数: |
3058 次 |
| 最近记录: |