[Python-Dev] Breaking bug #411881 into manageable pieces

Guido van Rossum guido@python.org
Wed, 20 Mar 2002 01:28:35 -0500


> Tim Peters <tim.one@comcast.net> writes:
> 
> > doctest.py: I Trust Tim (tm)
> > 
> >     Me too.  The first bare except is exec'ing arbitrary user-supplied
> >     code, and needs to catch everything.  The second needs to ignore
> >     any exception that may be raised by a user-define __str__, and
> >     that's any exception whatsoever, so ditto.
> 
> One observation in the bug report is that atleast KeyboardInterrupt
> needs to get a chance to get through, making bare except clauses evil
> under almost any circumstance. 
> 
> Regards,
> Martin

That would explain why sometimes I have to hit ^C twice to kill the
test suite.

There's a standard idiom for this:

  try:
    ...code...
  except KeyboardInterrupt:
    raise
  except:
    ...handler...

That's easy enough to add to doctest (I looked and it seems obvious
that this will work).

--Guido van Rossum (home page: http://www.python.org/~guido/)