[Django]-In Django Celery how can I tell if a task has been executed asynchronously

11👍

You can look at the is_eager or called_directly attributes of self.request within the task (the documentation currently isn’t very clear on the difference):

@app.task(bind=True)
def task_with_context(self, *args, **kwargs):
    print self.request.is_eager, self.request.called_directly

Leave a comment