I have a django app with some celery tasks, I'm staring worker with
celery -A myapp worker --loglevel=INFO --concurrency=10
I run task with task.deploy()
, but when I try to terminate task with celery.task.control.revoke(task_id, terminate=True)
I'm getting
[2015-07-27 14:27:04,736: ERROR/MainProcess] Task task[80e06e87-f254-4c0b-bea5-5c21540777ab] raised unexpected: Terminated(15,)
Traceback (most recent call last):
File "/home/blake/projects/venv/myapp/lib/python2.7/site-packages/billiard/pool.py", line 1674, in _set_terminated
raise Terminated(-(signum or 0))
Terminated: 15
I was looking for post about this error, but I have only found 3 years old post which didn't help me at all.
I'm using
celery==3.1.18
kombu==3.0.25
billiard==3.3.0.20
So how do I successfully terminate an already running task?
EDIT: Task is however being terminated but code stops executing because of exception and somehow except is not catching Exception
try:
revoke(task_id, terminate=True)
except Terminated:
pass
When creating task you need to specify the Exception which will be thrown inside task
from billiard.exceptions import Terminated
@task(throws=(Terminated,))
def task():
...