【发布时间】:2015-08-23 16:23:15
【问题描述】:
我有一个 celery 任务,它并行处理超大文本文件中的每一行。我还有一个 celery 任务,需要在处理完每一行后运行 - 它合并并处理每一行的输出。因为我正在使用这些庞大的数据集,有没有什么办法可以让 celery 与生成器一起工作,而不是列表?
def main():
header_generator = (processe.s(line) for line in file)
callback = finalize.s()
# Want to loop through header_generator and kick off tasks
chord(header_generator)(callback)
@celery.task
def process(line):
# do stuff with line, return output
return output
@celery.task
def finalize(output_generator):
# Want to loop through output_generator and process the output
for line in output_generator:
# do stuff with output
# do something to signal the completion of the file
如果这是不可能的——不用分叉芹菜——还有其他人可以推荐的策略吗?
【问题讨论】:
-
this post 有帮助吗?
标签: python celery task-queue