I'd like to quit a celery task gracefully (i.e. not by calling revoke(celery_task_id, terminate=True)
). I thought I'd send a message to the task that sets a flag, so that the task function can return. What's the best way to communicate with a task?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Use signals for this. Celery's
revoke
is the right choice; it uses SIGTERM by default, but you can specify another using thesignal
argument, if you prefer.Just set a signal handler for it in your task (using the
signal
module) that terminates the task gracefully.Also you can use an
AbortableTask
. I think this is the best way to stop task gracefully.http://docs.celeryproject.org/en/latest/reference/celery.contrib.abortable.html
If you save id task in somewhere you can call this whenever you want.