In general, raising asynchronous exceptions is difficult to handle properly. This is because instead of having single specific code codes where an exception can be thrown, and therefore when exception handling should be tested, an exception can be thrown after any bytecode instruction instead. This greatly complicates the implementation and fully checks for exception handling.
However, this can be done, but is currently not safe in Python. Increasing the asynchrony of an exception in Python is dangerous because you can raise it during the exception handler, which will lead to another exception and prevent incorrect cleaning. See My answer on How to limit the execution time of a function call in Python .
, Python. , .