celery doesn't work with global variable

前端 未结 2 629
小蘑菇
小蘑菇 2020-12-10 14:40
from celery import Celery

app = Celery(\'tasks\', backend=\'amqp://guest@localhost//\', broker=\'amqp://guest@localhost//\')

a_num = 0

@app.task
def addone():
            


        
2条回答
  •  感动是毒
    2020-12-10 15:28

    The tasks will run asynchronously so every time it starts a new task a_num will be set to 0. They are run as separate instances.

    If you want to work with values I suggest a value store or database of some sort.

提交回复
热议问题