billiard icon indicating copy to clipboard operation
billiard copied to clipboard

SoftTimeLimitExceeded inherits from Exception

Open wimby opened this issue 7 years ago • 4 comments

Hi, I am curious about why SoftTimeLimitExceeded inherits from Exception and not BaseException. Usually it's completely fine to write code like this:

try:
    x = something()
except Exception:
    logger.exception('Ouch')
    x = None

If it is normal script running in main thread, something like KeyboardInterrupt just terminates the script. In celery when SoftTimeLimitExceeded is raised, something is interrupted, but script will continue with None in x, so the script must be modified like this:

try:
    x = something()
except SoftTimeLimitExceeded:
    raise
except Exception:
    logger.exception('Ouch')
    x = None

Extending from BaseException (or SystemExit?) instead of Exception would solve this issue.

wimby avatar Feb 13 '18 10:02 wimby

bump :) anything I can help with ?

Twista avatar Mar 05 '18 10:03 Twista

Me too am curious. I would expect the (Soft)TimeLimit exceptions to be on pair with SystemExit exception - at least if I understand the functionality correctly. Is there any plan to look into this and change this behaviour?

rkuska avatar Apr 03 '18 10:04 rkuska

I also think this should be done, so should we make a PR? Or are any points against ?

jendagroovy avatar Aug 23 '18 08:08 jendagroovy

I also ran into this issue where I was expecting to cancel a long-running task by using

revoke(task_id, terminate=True, signal='SIGUSR1')

I happened to run into this issue because I was using boto3 which has an Exception catch block which wraps the original error.

It yielded the following:

botocore.exceptions.HTTPClientError: An HTTP Client raised an unhandled exception: SoftTimeLimitExceeded()

I suppose the issue at this point is that moving from Exception to BaseException is a breaking change.

kfreezen avatar Apr 18 '24 18:04 kfreezen