seen with the current 2.7 branch: $ cat > x.py def foo(): yield gen = foo() print gen.gi_frame.f_restricted for i in gen: pass print gen.gi_frame gen = foo() print gen.next() print gen.gi_frame.f_restricted $ python x.py False None None Segmentation fault Program received signal SIGSEGV, Segmentation fault. 0x0000000000462b44 in frame_getrestricted ( f=Frame 0x7ffff7f58410, for file x.py, line 1, in foo (), closure=0x0) at ../Objects/frameobject.c:383 383 ../Objects/frameobject.c: No such file or directory. (gdb) bt #0 0x0000000000462b44 in frame_getrestricted ( f=Frame 0x7ffff7f58410, for file x.py, line 1, in foo (), closure=0x0) at ../Objects/frameobject.c:383
This is related to the fix for issue 14432. gen_send_ex sets f->f_tstate to NULL, so PyFrame_IsRestricted segfaults: #define PyFrame_IsRestricted(f) \ ((f)->f_builtins != (f)->f_tstate->interp->builtins)
This appears to be 2.7 only as 3.4.2 stops on the first print with AttributeError: 'frame' object has no attribute 'f_restricted', which is not a crash.
The fix for issue 14432 was applied to 3.3, but I'm pretty sure 2.x PyFrame_IsRestricted is the only problem. Nothing else should see f_tstate when it's NULL. Also, f_tstate was dropped from PyFrameObject in 3.4.