BPB Online LLP
Internals of Python 3.x
Prashanth Raghu
Internals of Python 3.x
US$ 19.95
The publisher has enabled DRM protection, which means that you need to use the BookFusion iOS, Android or Web app to read this eBook. This eBook cannot be used outside of the BookFusion platform.
Description
Contents
Reviews

Deroute the syntactical way and start exploring the language from the source

Key Features
● In-depth practical understanding of CPython's internal workings.
● Step-by-step source code walkthrough utilizing descriptors on source code lines.
● Cutting-edge coverage of the interpreter, GIL, compilation, and memory allocations to help you develop better systems.

Description
Internals of Python 3.x transform a programmer's learning path by emphasizing the source code over the syntax to teach things from the ground up in nearly the same amount of time and effort.

The book delves into the structure and distinctions between the primary Python object and iterable objects. The iterable types, namely, lists and tuples, have been thoroughly defined in the structure and operations. The internals of sets and dictionaries, which are data structures that provide O(1) insertion and search, have been thoroughly discussed. Memory allocation explains how Python handles memory for tiny and large objects. The chapter on GIL explains how the GIL works, which is halted by a semaphore and a conditional variable. The chapter on Async Python describes how the async module generates coroutines and async functions that can be executed on an event loop and interact through events.

After reading this book, you will be more confident to create high-performance code on a day-to-day basis.

What you will learn
● Utilize data structures effectively for a variety of application functions.
● Discover how to optimize Python code performance.
● Develop an understanding of memory optimization and how to design programs accordingly.
● Investigate the inner working of GIL and Interpreter in detail.
● Recognize the internals of the garbage collection and reference counting processes.

Who this book is for
This book is intended for Python practitioners, new coding aspirants, and experienced Python developers who want to construct their frameworks and libraries by investigating tokenizers, parsers, code compilers, interpreters, memory management, GIL, and garbage collection. Prior programming skills in C may help you get the most out of this book.

Table of Contents
1. Design of Generic Objects
2. Basic Python Types
3. Iterable Sequence Objects
4. Set and Dictionary
5. Functions and Generators
6. Memory Management
7. Interpreter and Opcodes
8. GIL and Multithreading
9. Async Python
10. Source Code Layout and the Compiler Stages

Language
English
ISBN
9789391030940
Cover Page
Title Page
Copyright Page
Dedication Page
About the Author
About the Reviewer
Acknowledgement
Preface
Errata
Table of Contents
1. Design of Generic Objects
Structure
Objective
The PyObject
Understanding _PyObject_HEAD_EXTRA
Reference counting
The PyVarObject
The PyTypeObject
Generic type function prototypes
Specific type function prototypes
The type object substructures
The PyNumberMethods substructure
The PySequenceMethods substructure
The PyMappingMethods substructure
The type object
Name and sizes of type
Allocator, deallocator, and initialization functions
Iterator functions
Methods and attributes
Printing an instance of the type
Conclusion
2. Basic Python Types
Structure
Objectives
The Bool object
The Bool type
Creating a Boolean object
Representation of Boolean objects
Operations on Boolean objects
The Long object
The type of the Long object
Creating a new long object
Arithmetic operations
Bitwise operations
The Float object
The type object
Creating a new float object
Arithmetic operations
Comparison operations
The None object
The none type
Creation of the none object
Operations on the none object
Representation of the none object
Conclusion
3. Iterable Sequence Objects
Structure
Objective
The list object
The list type
Creating a list
Accessing an element in a list
Assigning an element in a list
Fetching the length of a list
Removing an element from the list
Freeing all the elements in the list
Checking an element in a list
List iteration
Fetching the iterator
Iterating the elements in the list
The tuple object
The tuple type
Creation of the tuple object
Hashing of the tuple object
Unpacking the elements in a tuple object
Conclusion
Reader exercises
4. Set and Dictionary
Structure
Objective
The set object
Structure of the set object
Creation of the set object
Adding an element to a set object
Iterating a set
Finding an element in a set
Union and intersection of sets
Dictionaries
Structure of a dictionary
Creating and inserting to dictionaries
Iterating dictionaries
Conclusion
5. Functions and Generators
Structure
Objective
Creation of the PyFunctionObject
The LOAD_CONST opcode
The MAKE_FUNCTION opcode
Function call
Structure of a function frame
CALL_FUNCTION opcode
Generators
Creating a generator
Creating an instance of a generator object
Structure of the generator object
Execution of a generator
Execution of the generator code
Conclusion
6. Memory Management
Structure
Objective
Memory management overview
Arenas
Arena memory management
Arena memory allocation
Arena memory deallocation
Memory pools
Structure of a memory pool
Memory allocation for objects
Pool table
Allocation lesser than SMALL_REQUEST_THRESHOLD
Conclusion
Reader exercises
7. Interpreter and Opcodes
Structure
Objectives
Opcodes
Python interpreter stack opcodes
Interpreter stack
Stack operation opcodes
Numerical operation opcodes
Matrix operation opcodes
Iterable opcodes
Looping opcodes
Branching opcodes
Implementation of the interpreter
Opcode prediction
Opcode dispatching and the GIL
Dispatch using computed go-tos
Dispatch without computed go-tos
Signal handling
Initializing signal handlers
Listening to signals
Signals and the interpreter
Conclusion
8. GIL and Multithreading
Structure
Objective
The GIL
Structure of GIL
Creating and initializing the GIL
Taking the GIL to access the interpreter
Relinquishing the GIL
Deallocating the GIL
Multithreading with the GIL
Conclusion
9. Async Python
Example
Structure
Objective
Coroutines
Continuing the execution of the coroutine
Asynchronous functions
Conclusion
10. Source Code Layout and the Compiler Stages
Structure
Objective
The folder structure of the Python source code
The main function
The Python grammar
Parse tree to abstract syntax tree
Operations on the parse tree
Navigation and conversion of the parse tree
Symbol table generation
Compilation to opcode
Conclusion
Index
The book hasn't received reviews yet.