[설치]
$ sudo apt install python-celery-common -y $ sudo apt-get install redis-server -y $ pip install celery $ pip install redis
[코딩]
# tasks.py from celery import Celery BROKER_URL = 'redis://localhost:6379/0' CELERY_RESULT_BACKEND = 'redis://localhost:6379/0' app = Celery('tasks', broker=BROKER_URL, backend=CELERY_RESULT_BACKEND) @app.task def add(x, y): return x + y
[실행]
$ celery -A tasks worker --loglevel=info
[호출]
>>> from tasks import add >>> add.delay(4, 4) >>> result = add.delay(4, 4) >>> result.ready() >>> result.get()
[참고]
1. 비동기 처리