Mark Shannon <m...@hotpy.org> added the comment: Jim Jewett wrote: > http://bugs.python.org/review/13897/diff/4186/14521 > File Python/sysmodule.c (right): > > http://bugs.python.org/review/13897/diff/4186/14521#newcode211 > Python/sysmodule.c:211: while ((exc_info->exc_type == NULL || > exc_info->exc_type == Py_None) && > This while loop is new, but it isn't clear how it is related to > encapsulating the exception state. Is this fixing an unrelated bug, or > is it from generators, or ..? > > http://bugs.python.org/review/13897/show
Running generators form a stack, much like frames. Calling a generator with next or send, pushes it onto the stack, yielding pops it. Now consider, if you will, the threadstate object as a sort of non-yielding (it cannot be popped) generator which forms the base of this stack. In this patch, rather than swapping the exception state between generator-owned frame and threadstate whenever entering or leaving a generator, each generator (and the threadstate) has its own exception state. It order to find the topmost exception state, sys.exc_info searches the stack of generators until it finds one. In practice the generator stack will be very shallow, only 1 or 2 deep, as it is rare to have generators calling other generators (although this will become a bit more common with PEP 380). ---------- title: Move fields relevant to sys.exc_info out of frame into generator/threadstate -> Move fields relevant to sys.exc_info out of frame into generator/threadstate _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13897> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com