Wildfire.py - Self-modifying Python bytecode
github.com
github.com
The most evil code I ever wrote [2] actually used this to modify the caller's bytecode in order to turn a log message into an exception with the correct stack trace from behind a C callback. I wouldn't recommend doing this, and I plan to excise this nasty hack at some point. Remarkably it works, even with a pretty intense multi-threaded unit test. I still don't like the idea of trusting this in production though.. You know the code in front of you must be evil if it contains a function named `re_execute_with_exception(frame, exception, traceback)`.
The problem is that the "correct" solution requires writing C/C++ code which we don't want to introduce to the project (distribution is a pain in the highly heterogeneous software environments that high energy physics has). The other correct solution is to fix upstream, which I hope will happen at some point. I look forward to the time when I can delete this code, anyway.
[1] https://code.google.com/p/byteplay/ [2] https://github.com/rootpy/rootpy/blob/master/rootpy/logger/m...
The big question this raises is: on a network of devices, what constitutes the operator's computer and what is the threshold past which execution would constitute distribution. It goes without saying that IANAL.
I don't know much about the underworld of Python, but is this kind of stuff similar to what PyPy does?
I started working on a visualizer for Python's AST (example [0]). I think it would be really cool to blend a lot of the functions of the underbelly of Python to see what's really happening. An AST side by side with a bytecode interpretation of it (or something). I haven't done too much looking, but there doesn't seem to be as much information about the inner workings of Python, just uses of it.
[0] http://imgur.com/IKXcoAp (I use Nodebox OpenGL for graphing)