【问题标题】:How do I pass a generator to celery.chord instead of a list?如何将生成器传递给 celery.chord 而不是列表?
【发布时间】: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

如果这是不可能的——不用分叉芹菜——还有其他人可以推荐的策略吗?

【问题讨论】:

标签: python celery task-queue


【解决方案1】:

在撰写本文时,传递给组和和弦的生成器会立即展开。我遇到了类似的问题,所以我添加了对它的支持并在这里创建了一个针对 celery 3.x 的拉取请求:https://github.com/celery/celery/pull/3043

目前只支持redis。希望 PR 将在 celery 3 发布之前合并。

【讨论】:

    猜你喜欢
    • 2016-08-14
    • 1970-01-01
    • 2014-09-23
    • 2019-02-20
    • 1970-01-01
    • 2016-04-28
    • 2019-08-02
    • 1970-01-01
    • 2022-12-09
    相关资源
    最近更新 更多