Message288010
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. |
|
Date |
User |
Action |
Args |
2017-02-17 14:23:48 | njs | set | recipients:
+ njs |
2017-02-17 14:23:48 | njs | set | messageid: <1487341428.62.0.272190755105.issue29590@psf.upfronthosting.co.za> |
2017-02-17 14:23:48 | njs | link | issue29590 messages |
2017-02-17 14:23:48 | njs | create | |
|