Concurrent asynchronous processes with Python, Flask and Celery

前端 未结 3 1109
故里飘歌
故里飘歌 2020-12-15 00:48

I am working on a small but computationally-intensive Python app. The computationally-intensive work can be broken into several pieces that can be executed concurrently. I a

3条回答
  •  北海茫月
    2020-12-15 01:20

    Use the Group feature of celery canvas:

    The group primitive is a signature that takes a list of tasks that should be applied in parallel.

    Here is the example provided in the documentation:

    from celery import group
    from proj.tasks import add
    
    g = group(add.s(2, 2), add.s(4, 4))
    res = g()
    res.get()
    

    Which outputs [4, 8].

提交回复
热议问题