Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard time limit does not run postrun signal #6077

Open
wilcoschoneveld opened this issue May 7, 2020 · 5 comments
Open

Hard time limit does not run postrun signal #6077

wilcoschoneveld opened this issue May 7, 2020 · 5 comments

Comments

@wilcoschoneveld
Copy link

wilcoschoneveld commented May 7, 2020

Here is a minimally reproducible testcase (tested against celery 4.4.2):

from celery import Celery
from celery.signals import task_postrun
import numpy as np

app = Celery('tasks', backend='rpc://', broker='pyamqp://guest@rabbit//')
app.conf.task_time_limit = 2

@app.task
def long_running_task():
    # this should take a couple of seconds
    return np.sum(np.random.rand(20000, 20000))


@task_postrun.connect
def task_postrun_handler(**kwargs):
    print("postrun handler", kwargs)

When long_running_task is interrupted with the TimeLimitExceeded exception, it does not run the postrun handler. This seems to happen only if the task is not easily interruptible (e.g. with a heavy numpy calculation instead of a simple while loop).

Related issue: #4932

@wilcoschoneveld
Copy link
Author

I've uploaded the minimal reproducible testcase here: https://github.com/wilcoschoneveld/celery-docker-quickstart/tree/timeout_failure (branch timeout_failure)

@auvipy
Copy link
Member

auvipy commented May 16, 2020

were you able to track down the root cause of this?

@xinydev
Copy link
Contributor

xinydev commented May 16, 2020

after hard time limit, the ForkPoolWorker is killed before it sends a postrun event.

postrun is sent from ForkPoolWorker while the kill signal is sent from main process. I think it may be a little hard to control the timing.

@wilcoschoneveld
Copy link
Author

@auvipy no

@Hsiny it only happens when the task is not easily interruptible like a heavy numpy calculation, but not with a simple python while True loop

@teodoroanca
Copy link

Did you manage to tackle this somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants