aiojobs icon indicating copy to clipboard operation
aiojobs copied to clipboard

Broken Scheduler.close() behavior on BaseException

Open himikof opened this issue 6 years ago • 3 comments

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.

himikof avatar May 10 '18 14:05 himikof

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.

asvetlov avatar May 11 '18 13:05 asvetlov

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.

himikof avatar May 14 '18 13:05 himikof

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.

asvetlov avatar May 17 '18 12:05 asvetlov