{"action":"created","issue":{"url":"https://api.github.com/repos/celery/celery/issues/2696","labels_url":"https://api.github.com/repos/celery/celery/issues/2696/labels{/name}","comments_url":"https://api.github.com/repos/celery/celery/issues/2696/comments","events_url":"https://api.github.com/repos/celery/celery/issues/2696/events","html_url":"https://github.com/celery/celery/issues/2696","id":93766357,"number":2696,"title":"Confusing behaviour when SoftTimeLimitExceeded is raised from task ","user":{"login":"dansondergaard","id":204911,"avatar_url":"https://avatars.githubusercontent.com/u/204911?v=3","gravatar_id":"","url":"https://api.github.com/users/dansondergaard","html_url":"https://github.com/dansondergaard","followers_url":"https://api.github.com/users/dansondergaard/followers","following_url":"https://api.github.com/users/dansondergaard/following{/other_user}","gists_url":"https://api.github.com/users/dansondergaard/gists{/gist_id}","starred_url":"https://api.github.com/users/dansondergaard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dansondergaard/subscriptions","organizations_url":"https://api.github.com/users/dansondergaard/orgs","repos_url":"https://api.github.com/users/dansondergaard/repos","events_url":"https://api.github.com/users/dansondergaard/events{/privacy}","received_events_url":"https://api.github.com/users/dansondergaard/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-08T11:25:10Z","updated_at":"2015-07-08T16:35:16Z","closed_at":null,"body":"Hi,\r\n\r\nIn my Celery task I catch the `SoftTimeLimitExceeded` exception and clean up appropriately. I then re-raise the exception with `raise SoftTimeLimitExceeded()` such that the task.result is the exception. I of course have `from celery.exceptions import SoftTimeLimitExceeded` at the top of my file.\r\n\r\nI now want to report to the user that the task timed out, so I wish to check if task.result is an instance of SoftTimeLimitExceeded. Basically, I have this in my Flask app:\r\n\r\n    if g.task.state in ('FAILURE', 'REVOKED'):\r\n        app.logger.debug(type(g.task.result))\r\n        app.logger.debug(isinstance(g.task.result, SoftTimeLimitExceeded))\r\n        if isinstance(g.task.result, SoftTimeLimitExceeded):\r\n            app.logger.debug('is instance!')\r\n            flash(('This error occurred since your job exceeded the time limit.'\r\n                   'Technical details can be found below.'), 'danger')\r\n        return render_template('failure.html', task=g.task)\r\n\r\nNow weird things happen. The first line that is logged is:\r\n\r\n    <class 'celery.backends.base.SoftTimeLimitExceeded'>\r\n\r\nThe second is:\r\n\r\n    False\r\n\r\nSo it seems that really some other exception is being raised, even though I raise exactly the exception I import. I then looked at `celery.backends.base` and found no reference to the exception in question. I wasn't able to import it with `from celery.backends.base import SoftTimeLimitExceeded`.\r\n\r\nWhat's happening here?"},"comment":{"url":"https://api.github.com/repos/celery/celery/issues/comments/119652173","html_url":"https://github.com/celery/celery/issues/2696#issuecomment-119652173","issue_url":"https://api.github.com/repos/celery/celery/issues/2696","id":119652173,"user":{"login":"thedrow","id":48936,"avatar_url":"https://avatars.githubusercontent.com/u/48936?v=3","gravatar_id":"","url":"https://api.github.com/users/thedrow","html_url":"https://github.com/thedrow","followers_url":"https://api.github.com/users/thedrow/followers","following_url":"https://api.github.com/users/thedrow/following{/other_user}","gists_url":"https://api.github.com/users/thedrow/gists{/gist_id}","starred_url":"https://api.github.com/users/thedrow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thedrow/subscriptions","organizations_url":"https://api.github.com/users/thedrow/orgs","repos_url":"https://api.github.com/users/thedrow/repos","events_url":"https://api.github.com/users/thedrow/events{/privacy}","received_events_url":"https://api.github.com/users/thedrow/received_events","type":"User","site_admin":false},"created_at":"2015-07-08T16:35:16Z","updated_at":"2015-07-08T16:35:16Z","body":"I'm not sure that this is the exception you want to raise. Maybe [abortable tasks](http://celery.readthedocs.org/en/latest/reference/celery.contrib.abortable.html) could help.\r\nI think that this exception is only being used in Celery internally."}}