[Python-Dev] Pre-PEP: Exception Reorganization for Python 3.0

James Y Knight foom at fuhm.net
Tue Aug 2 16:53:33 CEST 2005


On Aug 2, 2005, at 12:31 AM, Phillip J. Eby wrote:
> If you think that a KeyboardInterrupt is an error, then it's an  
> indication
> that Python's documentation and the current exception class  
> hierarchy has
> failed to educate you sufficiently, and that we *really* need to add a
> class like ControlFlowException into the hierarchy to help make  
> sure that
> other people don't end up sharing your misunderstanding.  ;-)

No... KeyboardInterrupt (just like other asynchronous exceptions)  
really should be treated as a critical error. Doing anything other  
than killing your process off after receiving it is just inviting  
disaster. Because the exception can have occurred absolutely  
anywhere, it is unsuitable for normal use. Aborting a function  
between two arbitrary bytecodes and trying to continue operation is  
simply a recipe for disaster. For example, in threadable.py between  
line 200 "saved_state = self._release_save()" and 201 "try:    #  
restore state no matter what (e.g., KeyboardInterrupt)" would be a  
bad place to hit control-c if you ever need to use that Condition  
again. This kind of problem is pervasive and unavoidable.

If you want to do a clean shutdown on control-c, the only sane way is  
to install a custom signal handler that doesn't throw an asynchronous  
exception at you.

There's a reason asynchronously killing off threads was deprecated in  
java.

James


More information about the Python-Dev mailing list