[Pyrex] [Cython] Pyrex exception reraise behavior

Stefan Behnel stefan_ml at behnel.de
Sun Aug 17 10:18:10 CEST 2008


Hi Greg,

Greg Ewing wrote:
> Stefan Behnel wrote:
> 
>> Greg Ewing wrote:
>>
>>> What you appear to be seeing is a leaking of the
>>> sys.exc_info() outside the scope where it would
>>> normally be available in Python.
>> Especially in Py3, where sys.exc_info() is reset when leaving the except block
>> that caught the exception.
> 
> But again, does this actually cause any problem?

Well, yes, the same problems for which the exception catching semantics were
redesigned in Py3. Leaving the exception in sys.exc_info will keep it alive
longer than necessary, even for an undefined period of time, as it will only
be deleted when the next exception is raised. In the case of an exception
raised by Python, this will keep alive all related frames in the traceback,
including their local variables etc. This can be expensive.

http://www.python.org/dev/peps/pep-0344/
http://www.python.org/dev/peps/pep-3110/

Stefan





More information about the Pyrex mailing list