-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
JobTimeoutException is derived from Exception which means that it can be mistakenly swallowed by the job function if it is doing it's own handling of unhandled exceptions.
def my_job(...) -> None:
try:
some_long_running_task()
except Exception as e:
handle_task_error(e)
Exception class is usually used for non-fatal exceptions caused directly by the application code. If you're injecting some exceptions via SIGALRM handling to indicate the need for ASAP finalization due to fatal error - BaseException is much better choice.
Actually that's pretty common problem e.g. https://docs.python.org/3/library/asyncio-exceptions.html#asyncio.CancelledError used to be derived from Exception as well until 3.8. They changed that because some coroutines performing their own exception handling were uncancellable: https://bugs.python.org/issue32528
I would normally make a PR but I noticed that in some places rq is possibly catching JobTimeoutException using except Exception as well. I'm not very familiar with the exception flow in the code but I saw such handling in few places: