exec(
code_fragment,
frame.f_globals,
frame.f_locals
)
# update locals
ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(frame), ctypes.c_int(0))
This sets the values back into the right place on the frame you were operating on.https://pydev.blogspot.jp/2014/02/changing-locals-of-frame-f...
See: https://gist.github.com/llllllllll/b1ac68a6b77535a64c0b13bfd... https://gist.github.com/dutc/d2ff9f17a0520d233b2d197d1dafa1a... https://twitter.com/__qualname__/status/867928378040438784
Alternative Python implementations do not follow all CPython implementation details.
In other words, if this is not part of the Python specification, it might work on other Python implementations even if it does not work on CPython.
Which is Java with Python syntax...
Last I collided with it, it was terribly slow, but that is not the point here.
Some of these alternative implementations are very interesting. PyPy is JIT'ed, and insanely fast compared to CPython. IronPython, IIRC, has no GIL.