"See CPython run: Getting to know your Python interpreter" - James Bennett (North Bay Python 2019)
Вставка
- Опубліковано 20 сер 2024
- James Bennett
2019.northbayp...
Python is a pretty neat language, but without an interpreter it doesn't do much. And although lots of people use the CPython interpreter (which is the main implementation of the Python language) every day, its workings are still a mystery even to many experienced Python programmers. So rather than explain features of Python the language, this talk will cover the interpreter itself, how it runs your code, and how you can use knowledge of the interpreter to figure out why your Python code behaves the way it does.
To get started, we'll briefly look at some real questions asked on Python forums, wondering about strange, or at least unexplained, behaviors of Python. Like: Why does a different way of writing the same code sometimes run faster? Why does the behavior of the `is` operator seem to be inconsistent for some kinds of values? And what's the deal with all those ".pyc" files Python likes to leave all over the place? How and where would we start looking for answers to these?
Then we'll take a look at the overall life cycle of Python code. We'll start with Python source code, and see how Python parses it into an abstract syntax tree (AST), how you can ask Python to show you the AST for a given piece of code, and how to read and understand it. Next we'll look at the transformation from AST to Python bytecode, what a Python code object looks like and how it's built, and how you can access it and understand the bytecode. Finally we'll see how the CPython virtual machine runs the compiled bytecode, and what's going on as it does so.
Then we'll dive into the infrastructure of the interpreter, pointing out where to go to see things like the low-level implementations of Python's built-in types, the bytecode interpreter loop, the AST and bytecode optimizers, and more, along with tips on how the interpreter's source code is organized and how to find and read things you're interested in.
Finally we'll circle back to some of the original questions about Python behavior, and see how they can be answered by using knowledge of how the CPython interpreter works, along with tools and tactics for making it easier to dig into what Python's doing with your code, and references for further reading and learning.
You might run a Python interpreter multiple times a day, but do you really know what it's doing while it runs your code? And if Python is doing something that seems strange, where might you start looking to figure out why? Come find out in this guided tour of how the CPython interpreter works!
A Python conference north of the Golden Gate
North Bay Python is a single-track conference with a carefully curated set of talks representing the diverse Python community and their different areas of interest.
If a topic is less to your interest, or you've met some people you really want to sit down and chat with, we'll have plenty of areas away from the main theatre to catch up and chat.
Our goal is to keep prices as low as possible. That means we won't be catering lunch. Instead, you can look forward to extra-long lunch breaks you can use to explore all of the great food options around the venue.
Produced by NDV: / @nextdayvideo
Sat Nov 2 14:30:00 2019 at Mystic Theatre