Description
Description:
Want to know what makes CPython interpreter's engine tick?
How about modifying Python's bytecode or maybe modifying it live in another running Python process?
Abstract:
In this talk we will go into what is in a Python .pyc file and how CPython executes that bytecode (mainly by looking at the code object). Afterwards we will talk about how to make simple modifications to the bytecode in order to insert hook points into preexisting code. We will see how we can use pyrasite for inspecting and modifying an already running Python process (useful for debugging long-running servers or detecting memory leaks). Finally, we will survey some more generic Python bytecode modifiers and code injectors.
Bonus points:
- How can CPython 2 (but not 3) can create valid yet unusable or wrong .pyc files from .py files? The talk will be based mainly on CPython 2.7.
- bytehook
- pyrasite
- codetransformer
- PTVS code injector
- that 20 years unclosed python 2 bug mentioned in the bonus points: ) + another timing quirk not documented.
Slides available here: http://il.pycon.org/2016/static/sessions/tom-zickel.pdf and here: http://tom.zickel.org/pyconil-2016