CPython is the
reference implementation
In the software development process, a reference implementation (or, less frequently, sample implementation or model implementation) is a program that implements all requirements from a corresponding specification. The reference implementation o ...
of the
Python programming language
Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.
Python is dynamically-typed and garbage-collected. It supports multiple programming p ...
. Written in
C and Python, CPython is the default and most widely used implementation of the Python language.
CPython can be defined as both an
interpreter and a
compiler
In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
as it compiles Python code into
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
before interpreting it. It has a
foreign function interface
A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written in another.
Naming
The term comes from the specification for Common Lisp, which explicit ...
with several languages, including C, in which one must explicitly write
bindings in a language other than Python.
Design
A particular feature of CPython is that it makes use of a
global interpreter lock
A global interpreter lock (GIL) is a mechanism used in computer-language interpreters to synchronize the execution of threads so that only one native thread (per process) can execute at a time. An interpreter that uses GIL always allows exactly o ...
(GIL) on each CPython interpreter
process
A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic.
Things called a process include:
Business and management
*Business process, activities that produce a specific se ...
, which means that within a single process, only one thread may be processing Python
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
at any one time. This does not mean that there is no point in
multithreading; the most common multithreading scenario is where
threads are mostly waiting on external processes to complete.
This can happen when multiple threads are servicing separate clients. One thread may be waiting for a client to reply, and another may be waiting for a
database
In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases sp ...
query to execute, while the third thread is actually processing Python code.
However, the GIL does mean that CPython is not suitable for processes that implement CPU-intensive algorithms in Python code that could potentially be distributed across multiple cores.
In real-world applications, situations where the GIL is a significant bottleneck are quite rare. This is because Python is an inherently slow language and is generally not used for CPU-intensive or time-sensitive operations. Python is typically used at the top level and calls functions in libraries to perform specialized tasks. These libraries are generally not written in Python, and Python code in another thread can be executed while a call to one of these underlying processes takes place. The non-Python library being called to perform the CPU-intensive task is not subject to the GIL and may concurrently execute many threads on multiple processors without restriction.
Concurrency of Python code can only be achieved with separate CPython interpreter processes managed by a
multitasking operating system
In computing, multitasking is the concurrent computing, concurrent execution of multiple tasks (also known as Process (computing), processes) over a certain period of time. New tasks can interrupt already started ones before they finish, inste ...
. This complicates communication between
concurrent Python processes, though the ''multiprocessing'' module mitigates this somewhat; it means that applications that really can benefit from concurrent Python-code execution can be implemented with a limited amount of
overhead.
The presence of the GIL simplifies the implementation of CPython, and makes it easier to implement multi-threaded applications that do not benefit from concurrent Python code execution. However, without a GIL, multiprocessing apps must make sure all common code is thread safe.
Although many proposals have been made to eliminate the GIL, the general consensus has been that in most cases, the advantages of the GIL outweigh the disadvantages; in the few cases where the GIL is a bottleneck, the application should be built around the multiprocessing structure.
History
Unladen Swallow
Unladen Swallow was an optimization branch of CPython, intended to be fully compatible and significantly faster. It aimed to achieve its goals by supplementing CPython's custom
virtual machine
In computing, a virtual machine (VM) is the virtualization/emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized hardw ...
with a
just-in-time compiler
In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is a way of executing computer code that involves compilation during execution of a program (at run time) rather than before execution. This may cons ...
built using
LLVM
LLVM is a set of compiler and toolchain technologies that can be used to develop a front end for any programming language and a back end for any instruction set architecture. LLVM is designed around a language-independent intermediate represen ...
.
The project had stated a goal of a speed improvement by a factor of five over CPython; this goal was not met.
The project was sponsored by
Google
Google LLC () is an American multinational technology company focusing on search engine technology, online advertising, cloud computing, computer software, quantum computing, e-commerce, artificial intelligence, and consumer electronics. ...
, and the project owners, Thomas Wouters, Jeffrey Yasskin, and Collin Winter, are full-time Google employees; however, most project contributors were not Google employees. Unladen Swallow was hosted on
Google Code
Google Developers (previously Google Code) , application programming interfaces (APIs), and technical resources. The site contains documentation on using Google developer tools and APIs—including discussion groups and blogs for developers usin ...
.
Like many things regarding the Python language, the name Unladen Swallow is a
Monty Python
Monty Python (also collectively known as the Pythons) were a British comedy troupe who created the sketch comedy television show '' Monty Python's Flying Circus'', which first aired on the BBC in 1969. Forty-five episodes were made over four ...
reference, specifically to the joke about the airspeed velocity of unladen
swallow
The swallows, martins, and saw-wings, or Hirundinidae, are a family of passerine songbirds found around the world on all continents, including occasionally in Antarctica. Highly adapted to aerial feeding, they have a distinctive appearance. The ...
s in ''
Monty Python and the Holy Grail
''Monty Python and the Holy Grail'' is a 1975 British comedy film satirizing the Arthurian legend, written and performed by the Monty Python comedy group (Graham Chapman, John Cleese, Terry Gilliam, Eric Idle, Terry Jones, and Michael Palin) an ...
''.
Although it fell short of all published goals, Unladen Swallow did produce some code that got added to the main Python implementation, such as improvements to the cPickle module.
In July 2010, some observers speculated on whether the project was dead or dying since the 2009 Q4 milestone had not yet been released. The traffic on Unladen's mailing list had decreased from 500 messages in January 2010 to fewer than 10 in September 2010. It has also been reported that Unladen lost Google's funding. In November 2010, one of the main developers announced that "Jeffrey and I have been pulled on to other projects of higher importance to Google".
The 2009 Q4 development branch was created on 26 January 2010, but no advertising was made on the website. Further, regarding the long-term plans, and as the project missed the Python 2.7 release, a
Python Enhancement Proposal
Python is a high-level programming language, high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of off-side rule, significant indentation.
Python is type_system#DYNAMIC, dynamically- ...
(PEP)
was accepted, which proposed a merge of Unladen Swallow into a special py3k-jit branch of Python's official
repository
Repository may refer to:
Archives and online databases
* Content repository, a database with an associated set of data management tools, allowing application-independent access to the content
* Disciplinary repository (or subject repository), an ...
. As of July 2010, this work was ongoing. This merging would have taken some time, since Unladen Swallow was originally based on Python 2.6 with which Python 3 broke compatibility (see
Python 3000
The programming language Python was conceived in the late 1980s, and its implementation was started in December 1989 by Guido van Rossum at CWI in the Netherlands as a successor to ABC capable of exception handling and interfacing with the ...
for more details). However, the PEP was subsequently withdrawn.
In early 2011, it became clear that the project was stopped.
Unladen Swallow release history
* 2009 Q1
* 2009 Q2
* 2009 Q3: reduce memory use, improve speed
Distribution
Officially supported tier-1 platforms are
Windows
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
,
Linux
Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
and
macOS
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
(and also
Raspberry Pi OS
Raspberry Pi OS (formerly Raspbian) is a Unix-like operating system based on the Debian Linux distribution for the Raspberry Pi family of compact single-board computers. First developed independently in 2012, it has been produced as the primary o ...
, and Linux for
s390x
Linux on IBM Z or Linux on zSystems is the collective term for the Linux operating system compiled to run on IBM mainframes, especially IBM Z / IBM zSystems and IBM LinuxONE servers. Similar terms which imply the same meaning are ''Linux/390'', ...
on lower tier).
There are more platforms that have working implementations including:
; Unix-like:
; Special and embedded:
; Other:
PEP 11 lists platforms which are not supported in CPython by the
Python Software Foundation
The Python Software Foundation (PSF) is an American nonprofit organization devoted to the Python programming language, launched on March 6, 2001. The mission of the foundation is to foster development of the Python community and is responsible for ...
. These platforms can still be supported by external ports. These ports include:
External ports not integrated to Python Software Foundation's official version of CPython, with links to its main development site, often include additional modules for platform-specific functionalities, like graphics and sound API for PSP and SMS and camera API for S60. These ports include:
Enterprise Linux
These Python versions are distributed with currently-supported enterprise Linux distributions. The support status of Python in the table refers to support from the Python core team, and not from the distribution maintainer.
Alternatives
CPython is one of several "production-quality"
Python implementations including:
Jython
Jython is an implementation of the Python programming language designed to run on the Java platform. The implementation was formerly known as JPython until 1999.
Overview
Jython programs can import and use any Java class. Except for some standa ...
, written in
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
for the
Java virtual machine
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
(JVM),
PyPy
PyPy () is an implementation of the Python programming language. PyPy often runs faster than the standard implementation CPython because PyPy uses a just-in-time compiler. Most Python code runs well on PyPy except for code that depends on CPytho ...
, written in
RPython
PyPy () is an implementation of the Python programming language. PyPy often runs faster than the standard implementation CPython because PyPy uses a just-in-time compiler. Most Python code runs well on PyPy except for code that depends on CPytho ...
and translated into C, and
IronPython
IronPython is an implementation of the Python programming language targeting the .NET Framework and Mono. Jim Hugunin created the project and actively contributed to it up until Version 1.0 which was released on September 5, 2006. IronPython 2.0 ...
, which is written in
C# for the
Common Language Infrastructure
The Common Language Infrastructure (CLI) is an open specification and technical standard originally developed by Microsoft and standardized by ISO/IEC (ISO/IEC 23271) and Ecma International (ECMA 335) that describes executable code and a runt ...
. There are also several experimental implementations.
References
Further reading
*
External links
*
{{Python (programming language)
Free compilers and interpreters
Free software programmed in C
Python (programming language) implementations
Software using the PSF license
Free software programmed in Python
Stack-based virtual machines