[Python-Dev] Proposal - KeyboardInterrupt should inherit directly from Exception

M.-A. Lemburg mal@lemburg.com
Wed, 07 Nov 2001 22:05:42 +0100


Skip Montanaro wrote:
> 
>     Greg> Hmmm... does anyone else habitually write
> 
>     Greg>   if __name__ == "__main__":
>     Greg>       try:
>     Greg>           main()
>     Greg>       except KeyboardInterrupt:
>     Greg>           sys.exit("interrupted")
> 
> This suggests one other enhancement to me.  Just as raising SystemExit
> doesn't generate a traceback, perhaps the default handling of
> KeyboardInterrupt could be configurable so I could set (for example):
> 
>     sys.gen_kbi_traceback = 0
>     sys.gen_kbi_message = 0
> 
> to suppress traceback and/or message output without having to do
> explicitly catch it.  The default for both would be 1 to remain
> compatible with current behavior.  If you caught the exception, these
> would have no effect.

Isn't this already possible using one of the display hooks in
sys, e.g. sys.excepthook() ?!

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/