aiojobs
aiojobs copied to clipboard
Broken Scheduler.close() behavior on BaseException
If a BaseException
which is not an Exception
is thrown inside a job (for example, KeyboardInterrupt
), the Scheduler._wait_failed()
task fails to catch this exception after re-raising it, and this exception gets raised from the Scheduler.close()
method (due to await self._failed_task
), which is totally unexpected.
Probably the intended invariant in Scheduler._wait_failed()
was to never raise an exception.
It is the hard question.
By catching KeyboardInterrupt
user has no chance to stop the program.
I don't sure if the behavior should be changed.
No, the application has already received the KeyboardInterrupt
(by awaiting the job future), and is in the process of graceful shutdown (in the exception handler). In the process of the shutdown it calls Scheduler.close()
, which unexpectedly raises another KeyboardInterrupt
, which then aborts the graceful termination.
I have a feeling that the problem should be fixed by asyncio itself somehow, not by aiojobs.
Otherwise, every asyncio library should catch and process KeyboardInterrupt
on every await
expression.