Author njs
Recipients njs
Date 2017-02-17.14:23:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487341428.62.0.272190755105.issue29590@psf.upfronthosting.co.za>
In-reply-to
Content
The attached script sets up a stack of generators calling each other via 'yield from': f yields from g yield from h. Then the generator at the bottom of the stack yields.

Before they yield, sys._getframe shows the expected stack (or if you put in traceback.print_stack() you get the same thing).

After they yield, it depends: if the generator is resumed via 'gen.send(None)', then the stack looks sensible. But if the generator is resumed via 'gen.throw(...)', then the stack is weird: Objects/genobject.c:_gen_throw implements 'yield from' in an weird manual way, where it first directly resumes the innermost generator frame, and then propagates any result to the next generator frame, etc. So the output I get from the sample script is:

~$ python3.6 weird-throw-stack.py
-- f before yielding --
f
<module>
-- g before yielding --
g
f
<module>
-- h before yielding --
h
g
f
<module>
-- h after yielding --
h
<module>
-- g after yielding --
g
<module>
-- f after yielding --
f
<module>

This causes problems for stack-based profiling (https://github.com/vmprof/vmprof-python/issues/117), debuggers, and other tools that need to introspect the stack.
History
Date User Action Args
2017-02-17 14:23:48njssetrecipients: + njs
2017-02-17 14:23:48njssetmessageid: <1487341428.62.0.272190755105.issue29590@psf.upfronthosting.co.za>
2017-02-17 14:23:48njslinkissue29590 messages
2017-02-17 14:23:48njscreate