This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author arigo
Recipients
Date 2004-08-16.11:23:45
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
The core uses PyErr_Clear() in quite a number of places, which is bad.  It can hide a genuine problem like a MemoryError or an infinite recursion.  Fixing all these places is very difficult: there are a lot of functions that pretend they can't fail.  Instead, the current patch extends the asynchronous thread exception mecanism recently introduced, and PyErr_Clear() sends such an asynchronous exception to the current thread if it detects an exception that should not be lost.

"Should not be lost" is defined as subclassing from the new AsyncronousException class.  The exception hierarchy now looks like:

Exception
|
+-- SystemExit
|
+-- StopIteration
|
+-- StandardError
|   +-- almost_all_the_XxxError
|
+-- AsynchronousException
|   +-- KeyboardInterrupt
|   +-- RuntimeError
|   +-- MemoryError
|
+-- Warning

Some more thinking about it would be welcome.  Maybe AsynchronousException and a few others should not subclass Exception at all, so that "except Exception" statements don't catch them.  Anyway, this patch alreaddy improves the situation, because you can catch and re-raise AsynchronousException (instead of, say, just KeyboardInterrupt).

Incompatibility note: in CVS, NotImplementedError is a subclass of RuntimeError.  With this patch it doesn't make sense any more, so NotImplementedError now inherits directly from StandardError.

Finally note that the patch is a first draft, not really tested and documented (though it's already nice to be able to Ctrl-C out of a long-running hasattr() call).  In particular I'm not entierely sure when the asynchronous exception will be re-raised (though it should always be shortly after the original faulty opcode).  I'm not sure the tracebacks coming from such exceptions will always be correct (e.g. they could point to a point after the one that triggered the exception, or even skip a few recursion levels entierely).

Assigning to mwh because he seems interested in the idea.
History
Date User Action Args
2007-08-23 15:39:25adminlinkissue1009929 messages
2007-08-23 15:39:25admincreate