Celery task timeout/time limit for windows?
If you really need to set the task timeout, you can use the child process to achieve, the code as follows
import jsonfrom multiprocessing import Processfrom celery import current_appfrom celery.exceptions import SoftTimeLimitExceededsoft_time_limit = 60@current_app.task(name="task_name")def task_worker(self, *args, **kwargs): def on_failure(): pass worker = Process(target=do_working, args=args, kwargs=kwargs, name='worker') worker.daemon = True worker.start() worker.join(soft_time_limit) while worker.is_alive(): worker.terminate() raise SoftTimeLimitExceeded return json.dumps(dict(message="ok"))def do_working(*args, **kwargs): pass # do something
It doesn't look like there is any built in workaround for this in Celery. Could you perhaps code this into your task directly? In other words, in your python code, start a timer when you begin the task, if the task takes too long to complete, raise an exception, and resubmit the job to the queue again.