Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

softtimeout and timeout in celery tasks don't work

Tags:

python

celery

I have a task that takes 20 seconds in average. I want to set soft and hard timeout for this task. I define it like this:

@app.task(ignore_result=True, timeout=100, soft_timeout=50)
def MYTASK(SOMEPARAMS):
     # MYTASK

But it doesn't work really. I test it with this params:

@app.task(ignore_result=True, timeout=1, soft_timeout=1)
def MYTASK(SOMEPARAMS):
     # MYTASK

But my tasks work correctly and them takes times over 1 seconds while it should never be done.

why timeout doesn't work?

Edit: When I use 1 sec timeout in my log I see prints like this:

[2014-08-22 12:51:00,003: INFO/MainProcess] Task MYTASK[56002e72-a093-46c6-86cd-4c7b7e6ea7c3] succeeded in 15.549023876s: None
like image 934
Vahid Kharazi Avatar asked Oct 01 '22 00:10

Vahid Kharazi


1 Answers

Use time_limit and soft_time_limit parameters:

@task(time_limit=2, soft_time_limit=1)
def mytask():
    pass

Also note, that:

Time limits do not currently work on Windows and other platforms that do not support the SIGUSR1 signal.

like image 106
alex vasi Avatar answered Oct 03 '22 03:10

alex vasi