[New-bugs-announce] [issue5970] sys.exc_info leaks into a generator

Jeffrey Yasskin report at bugs.python.org
Fri May 8 19:44:01 CEST 2009

New submission from Jeffrey Yasskin <jyasskin at gmail.com>:

There's an obscure bug in sys.exc_info after a yield statement.

  def test():
      def raising_generator():
              raise IndexError("inner exception")
          except IndexError:
              yield 3
              # Here, sys.exc_info() ought to refer to the inner
              # exception, but instead it refers to the outer one.
          raise ValueError("outer exception")
      except ValueError:
          for i in raising_generator(): pass

sys.exc_info gets reset even if there's no outer exception.

The attached (failing) patch highlights this problem, and tests other
sys.exc_info behavior around function calls.

components: Interpreter Core
files: exc_info.patch
keywords: patch
messages: 87452
nosy: collinwinter, jyasskin
priority: low
severity: normal
stage: needs patch
status: open
title: sys.exc_info leaks into a generator
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1
Added file: http://bugs.python.org/file13927/exc_info.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list