We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Elizaveta Shashkova - The Hidden Power of the Python Runtime
Explore the hidden power of the Python runtime, including debuggers, frame objects, and the inspect module, to gain a deeper understanding of program execution and optimize your code.
- Python runtime provides a lot of useful information, but it’s hidden from users and available only during execution.
- Debuggers are cool tools that help find bugs and understand program execution.
-
sys.getframe()
andsys.currentFrame()
can be used to get the current frame object. - A frame object contains information about the current program scope, such as local and global variables, corresponding code object, and more.
- Code object represents a chunk of executable code and contains information about the file name, function name, and line number.
-
inspect
module provides functions to inspect frame objects and program scope. - Profiling function and tracing function are used in debuggers to analyze program execution.
- Frame evaluation function is used to evaluate the result of some code.
- There are two ways to execute tasks concurrently in Python: threads and asynchronous tasks.
- Dead logs can occur when threads are waiting for resources that can’t be released.
-
coverage.py
is a popular code coverage library that uses tracing function and record types of function arguments. - A code object knows about the file name, where it was created, and the name of the function or module where it was defined.
-
Local and global variables can be accessed using
locals()
andglobals()
functions. - Frame object contains a dictionary of local variables, where keys are their names and values are variable objects.
- Asynchronous tasks are similar to real threads and have the same synchronization objects.
-
inspect.getSource()
function can be used to get the source code represented as a string and line number.