[New-bugs-announce] [issue20317] ExitStack hang if enough nested exceptions

jcflack report at bugs.python.org
Mon Jan 20 21:08:09 CET 2014

New submission from jcflack:

Python 3.3.2 (default, Dec  4 2013, 20:19:27) 
[GCC 4.7.3] on linux (gentoo)

Suppose we create a context manager that will fail during exit because of a simple coding error:

def f():
  yield 6
  throdbog() # woops, forgot to define this

Now let's stack up a few of these:

with ExitStack() as stack:
 i = stack.enter_context(f())
 i = stack.enter_context(f())
 i = stack.enter_context(f())

... prints 6, then hangs, won't respond to ^C, can be killed.

Three levels on the stack seems to be the magic number. With one or two it works as expected ("During handling of the above exception, another exception occurred", etc.).

Is the ExitStack code somehow creating a circularly-linked exception structure when there are three levels?

components: Library (Lib)
messages: 208574
nosy: jcflack
priority: normal
severity: normal
status: open
title: ExitStack hang if enough nested exceptions
type: crash
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list