CPython

Last updated
CPython
Original author(s) Guido van Rossum
Developer(s) Python core developers and the Python community, supported by the Python Software Foundation
Initial release26 January 1994;29 years ago (1994-01-26)
Stable release
3.12.0 [1]   OOjs UI icon edit-ltr-progressive.svg / 2 October 2023;3 months ago (2 October 2023)
Repository https://github.com/python/cpython
Written in C, Python
Platform 42 platforms; see § Distribution
Available in English
Type Python Programming Language Interpreter
License Python Software Foundation License
Website www.python.org

CPython is the reference implementation of the Python programming language. Written in C and Python, CPython is the default and most widely used implementation of the Python language.

Contents

CPython can be defined as both an interpreter and a compiler as it compiles Python code into bytecode before interpreting it. It has a foreign function interface 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 (GIL) on each CPython interpreter process, which means that within a single process, only one thread may be processing Python bytecode at any one time. [2] 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 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. 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 limited 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. To help allow more parallelism, an improvement was released in October 2023 to allow a separate GIL per subinterpreter in a single Python process and have been described as "threads with opt-in sharing". [3] [4]

After several debates, a project was launched in 2023 to propose making the GIL optional from version 3.13 of Python, [5] which is scheduled for release in October 2024. [6]

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 with a just-in-time compiler built using LLVM.

The project had stated a goal of a speed improvement by a factor of five over CPython; [7] this goal was not met. [8]

The project was sponsored by Google, and the project owners, Thomas Wouters, Jeffrey Yasskin, and Collin Winter, are full-time Google employees; however, most project contributors were not Google employees. [9] Unladen Swallow was hosted on Google Code. [10]

Like many things regarding the Python language, the name Unladen Swallow is a Monty Python reference, specifically to the joke about the airspeed velocity of unladen swallows in Monty Python and the Holy Grail .

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. [11]

In July 2010, some observers speculated on whether the project was dead or dying since the 2009 Q4 milestone had not yet been released. [12] The traffic on Unladen's mailing list had decreased from 500 messages in January 2010 to fewer than 10 in September 2010. [13] It has also been reported that Unladen lost Google's funding. [14] 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." [15]

The 2009 Q4 development branch was created on 26 January 2010, [16] 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 (PEP) [8] was accepted, which proposed a merge of Unladen Swallow into a special py3k-jit branch of Python's official repository. As of July 2010, this work was ongoing. [17] This merging would have taken some time, since Unladen Swallow was originally based on Python 2.6 [18] with which Python 3 broke compatibility (see Python 3000 for more details). However, the PEP was subsequently withdrawn.

In early 2011, it became clear that the project was stopped. [19]

Unladen Swallow release history

  • 2009 Q1 [20]
  • 2009 Q2 [21]
  • 2009 Q3: reduce memory use, improve speed [22]

Distribution

Officially supported tier-1 platforms are Windows, Linux, and macOS. (Also Raspberry Pi OS, and Linux for s390x on lower tier.)

More platforms have working implementations, including: [23]

Unix-like
Special and embedded
Other

PEP 11 [24] lists platforms which are not supported in CPython by the Python Software Foundation. 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. [33] The support status of Python in the table refers to support from the Python core team, and not from the distribution maintainer.

Enterprise Linux
Distribution versionDistribution end-of-life Python version
Ubuntu 22.04 LTS (Jammy Jellyfish)3.10
Ubuntu 20.04 LTS (Focal Fossa)2030-04 [34] [ needs update ] [35] Older version, yet still maintained: 3.8 [36]
Ubuntu 18.04 LTS (Bionic Beaver)2028-04 [37] Old version, no longer maintained: 2.7 [38] Old version, no longer maintained: 3.6 [39]
Ubuntu 16.04 LTS (Xenial Xerus)2021-04-30 [40] [ needs update ]Old version, no longer maintained: 2.7 [38] Old version, no longer maintained: 3.5 [39]
Debian 122028-06 [41] Older version, yet still maintained: 3.11 [41]
Debian 112026-06 [42] Older version, yet still maintained: 3.9 [42]
Debian 102024-06 [43] Old version, no longer maintained: 2.7 [44] Older version, yet still maintained: 3.7 [45] [ needs update ]
Debian 92022-06-30 [46] [ needs update ]Old version, no longer maintained: 2.7 [47] Old version, no longer maintained: 3.5 [48]
Red Hat Enterprise Linux 82029Old version, no longer maintained: 2.7 [49] Old version, no longer maintained: 3.6
Red Hat Enterprise Linux 72024-11-30 [50] Old version, no longer maintained: 2.7 [51]
CentOS 82029-05-31Old version, no longer maintained: 2.7Old version, no longer maintained: 3.6
CentOS 72024-06-30Old version, no longer maintained: 2.7 [52]
SUSE Linux Enterprise Server 152031-07-31Old version, no longer maintained: 2.7 [53] Old version, no longer maintained: 3.6
SUSE Linux Enterprise Server 122027-10-31Old version, no longer maintained: 2.7 [54]
SUSE Linux Enterprise Server 112022-03-31[ needs update ]Old version, no longer maintained: 2.7 [54]
Legend:
Old version
Older version, still maintained
Latest version
Latest preview version
Future release

Alternatives

CPython is one of several "production-quality" Python implementations including: Jython, written in Java for the Java virtual machine (JVM), PyPy, written in RPython and translated into C, and IronPython, which is written in C# for the Common Language Infrastructure. There are also several experimental implementations. [55]

Related Research Articles

<span class="mw-page-title-main">Linux distribution</span> Operating system based on the Linux kernel

A Linux distribution is an operating system made from a software collection that includes the Linux kernel and often a package management system. Linux users usually obtain their operating system by downloading one of the Linux distributions, which are available for a wide variety of systems ranging from embedded devices and personal computers to powerful supercomputers.

<span class="mw-page-title-main">UEFI</span> Operating system and firmware specification

Unified Extensible Firmware Interface is a specification that defines the architecture of the platform firmware used for booting the computer hardware and its interface for interaction with the operating system. Examples of firmware that implement the specification are AMI Aptio, Phoenix SecureCore, TianoCore EDK II, InsydeH2O. UEFI replaces the BIOS which was present in the boot ROM of all personal computers that are IBM PC compatible, although it can provide backwards compatibility with the BIOS using CSM booting. Intel developed the original Extensible Firmware Interface (EFI) specification. Some of the EFI's practices and data formats mirror those of Microsoft Windows. In 2005, UEFI deprecated EFI 1.10.

Software versioning is the process of assigning either unique version names or unique version numbers to unique states of computer software. Within a given version number category, these numbers are generally assigned in increasing order and correspond to new developments in the software. At a fine-grained level, revision control is used for keeping track of incrementally-different versions of information, whether or not this information is computer software, in order to be able to roll any changes back.

phpLDAPadmin is a web app for administering Lightweight Directory Access Protocol (LDAP) servers. It's written in the PHP programming language, and is licensed under the GNU General Public License. The application is available in 14 languages and supports UTF-8 encoded directory strings.

IronPython is an implementation of the Python programming language targeting the .NET and Mono frameworks. The project is currently maintained by a group of volunteers at GitHub. It is free and open-source software, and can be implemented with Python Tools for Visual Studio, which is a free and open-source extension for Microsoft's Visual Studio IDE.

<span class="mw-page-title-main">PyPy</span> Alternative implementation of the Python programming language

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 CPython extensions, which either does not work or incurs some overhead when run in PyPy. Internally, PyPy uses a technique known as meta-tracing, which transforms an interpreter into a tracing just-in-time compiler. Since interpreters are usually easier to write than compilers, but run slower, this technique can make it easier to produce efficient implementations of programming languages. PyPy's meta-tracing toolchain is called RPython.

Freespire is a community-driven Linux distribution currently owned by PC/Open Systems LLC. It is derived from Linspire and is composed mostly of free, open source software, while providing users the choice of including proprietary software including multimedia codecs, device drivers and application software.

<span class="mw-page-title-main">Compiz</span> Compositing window manager for the X Window System

Compiz is a compositing window manager for the X Window System, using 3D graphics hardware to create fast compositing desktop effects for window management. Effects, such as a minimization animation or a cube workspace, are implemented as loadable plugins. Because it conforms to the ICCCM conventions, Compiz can be used as a substitute for the default Mutter or Metacity, when using GNOME Panel, or KWin in KDE Plasma Workspaces. Internally Compiz uses the OpenGL library as the interface to the graphics hardware.

<span class="mw-page-title-main">PulseAudio</span> Sound server for Unix-like operating systems

PulseAudio is a network-capable sound server program distributed via the freedesktop.org project. It runs mainly on Linux, including Windows Subsystem for Linux on Microsoft Windows and Termux on Android; various BSD distributions such as FreeBSD, OpenBSD, and macOS; as well as Illumos distributions and the Solaris operating system. It serves as a middleware in between applications and hardware and handles raw PCM audio streams.

<span class="mw-page-title-main">Linux</span> Family of Unix-like operating systems

Linux 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 (distro), which includes the kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses and recommends the name "GNU/Linux" to emphasize the use and importance of GNU software in many distributions, causing some controversy.

<span class="mw-page-title-main">MonoDevelop</span> Integrated development environment, discontinued for macOS

MonoDevelop was an open-source integrated development environment for Linux, macOS, and Windows. Its primary focus is development of projects that use Mono and .NET Framework. MonoDevelop integrates features similar to those of NetBeans and Microsoft Visual Studio, such as automatic code completion, source control, a graphical user interface (GUI) and Web designer. MonoDevelop integrates a Gtk# GUI designer called Stetic. It supports Boo, C, C++, C#, CIL, D, F#, Java, Oxygene, Vala, JavaScript, TypeScript and Visual Basic.NET. Although there is no word from the developers that it has been discontinued, nonetheless it hasn't been updated in 4 years and is no longer installable on major operating systems, such as Ubuntu 22.04 and above. Its parent Microsoft, seems to have shifted focus to Visual Studio Code and the .NET Framework, which runs on many operating systems, including Linux.

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 can execute at a time. An interpreter that uses GIL always allows exactly one thread to execute at a time, even if run on a multi-core processor. Some popular interpreters that have GIL are CPython and Ruby MRI.

<span class="mw-page-title-main">WeeChat</span> IRC client

WeeChat is a free and open-source Internet Relay Chat client that is designed to be light and fast. It is released under the terms of the GNU GPL-3.0-or-later and has been developed since 2003.

<span class="mw-page-title-main">KVIrc</span> IRC Client

KVIrc is a graphical IRC client for Linux, Unix, Mac OS and Windows. The name is an acronym of K Visual IRC in which the K stands for a dependency to KDE, which became optional from version 2.0.0. The software is based on the Qt framework and its code is released under a modified GNU General Public License.

Software distribution is the process of delivering software to the end user.

<span class="mw-page-title-main">Leafpad</span> Lightweight text editor

Leafpad is a free and open-source graphical text editor for Linux, Berkeley Software Distribution (BSD), and Maemo that is similar to the Microsoft Windows program Notepad. Created with the focus of being a lightweight text editor with minimal dependencies, it is designed to be simple-to-use and easy-to-compile.

<span class="mw-page-title-main">Linspire</span> Linux distribution

Linspire is a commercial operating system based on Debian and Ubuntu and currently owned by PC/OpenSystems LLC. It had been owned by Linspire. Inc. from 2001 to 2008, and then by Xandros from 2008 to 2017.

<span class="mw-page-title-main">Thonny</span> Python IDE

Thonny is a free and open-source integrated development environment for Python that is designed for beginners. It was created by Aivar Annamaa, an Estonian programmer. It supports different ways of stepping through code, step-by-step expression evaluation, detailed visualization of the call stack and a mode for explaining the concepts of references and heap.

References

  1. Thomas Wouters (2 October 2023). "Python 3.12.0 (final) is here".
  2. "Initialization, Finalization, and Threads". Python v3.8.3 documentation. Retrieved 2020-06-04.
  3. Jake Edge (August 15, 2023). "A per-interpreter GIL". LWN. Retrieved 2024-01-13.
  4. "PEP 684 – A Per-Interpreter GIL | peps.python.org" . Retrieved 2024-01-13.
  5. "PEP 703 – Making the Global Interpreter Lock Optional in CPython | peps.python.org". peps.python.org. Retrieved 2023-09-17.
  6. "PEP 719 – Python 3.13 Release Schedule | peps.python.org". peps.python.org. Retrieved 2023-09-17.
  7. Paul, Ryan (2009-03-26). "Ars Technica report on Unladen Swallow goals". Arstechnica.com. Retrieved 2011-08-19.
  8. 1 2 Winter, Collin; Yasskin, Jeffrey; Kleckner, Reid (2010-03-17). "PEP 3146 - Merging Unladen Swallow into CPython". Python.org.
  9. "People working on Unladen Swallow". Archived from the original on 2015-10-29. Retrieved 2019-08-08.
  10. "Unladen Swallow project page" . Retrieved 2011-08-19.
  11. "Issue 9410: Add Unladen Swallow's optimizations to Python 3's pickle. - Python tracker". bugs.python.org. Retrieved 2019-08-08.
  12. "Message on comp.lang.python" . Retrieved 2011-08-19.
  13. "Unladen Swallow | Google Groups" . Retrieved 2011-08-19.
  14. "reddit post by an Unladen committer". Reddit.com. 2010-06-24. Retrieved 2011-08-19.
  15. Winter, Collin (8 November 2010). "Current status of Unladen-Swallow".
  16. "2009 Q4 release branch creation". 2010-01-26. Retrieved 2011-08-19.
  17. "Developers focus on merge into py3k-jit". 2010-07-13. Retrieved 2011-08-19.
  18. "Unladen Swallow baseline". Python.org. Retrieved 2011-08-19.
  19. Kleckner, Reid (26 March 2011). "Unladen Swallow Retrospective". QINSB is not a Software Blog (qinsb.blogspot.com).
  20. "Unladen Swallow 2009Q1". unladen-swallow, A faster implementation of Python. Retrieved 19 October 2012.
  21. "Unladen Swallow 2009Q2". unladen-swallow, A faster implementation of Python. Retrieved 19 October 2012.
  22. "Unladen Swallow 2009Q3". unladen-swallow, A faster implementation of Python. Retrieved 19 October 2012.
  23. "PythonImplementations" . Retrieved 19 July 2012.
  24. "PEP 11 -- Removing support for little used platforms". Python.org. Retrieved 2019-08-08.
  25. "Irix still supported?". 14 February 2009.
  26. AmigaPython
  27. iSeriesPython
  28. PythonD
  29. http://yellowblue.free.fr/yiki/doku.php/en:dev:python:start Python 2 and 3
  30. Stackless Python for PSP
  31. Python Windows CE port
  32. "Python". VSI. Retrieved 2021-08-31.
  33. "Support Life Cycles for Enterprise Linux Distributions". Archived from the original on 2022-08-30. Retrieved 2017-10-15.
  34. "Ubuntu release cycle". Ubuntu. Retrieved 2021-01-18.
  35. "With Python 2 EOL'ed, Ubuntu 20.04 LTS Moves Along With Its Python 2 Removal - Phoronix". phoronix.com. Retrieved 2020-04-01.
  36. "Binary package "python3" in ubuntu focal". Launchpad.net.
  37. "Ubuntu 18.04 extended to 2028". ServerWatch.com. 2018-11-15. Retrieved 2019-09-09.
  38. 1 2 "python-defaults package: Ubuntu". Canonical Ltd. 2018-06-08. Retrieved 2018-06-08.
  39. 1 2 "python3-defaults package: Ubuntu". Canonical Ltd. 2018-06-08. Retrieved 2018-06-08.
  40. Science, Carnegie Mellon University School of Computer. "Ubuntu 16.04 - End of Life in 2021 - SCS Computing Facilities - Carnegie Mellon University". computing.cs.cmu.edu. Retrieved 2021-02-15.
  41. 1 2 "Debian 12 bookworm released". debian.org.
  42. 1 2 "Debian -- News -- Debian 11 "bullseye" released". debian.org. Retrieved 2022-01-04.
  43. "LTS - Debian Wiki". wiki.debian.org. Retrieved 2021-02-15.
  44. "Debian -- Details of package python in buster". packages.debian.org. Retrieved 2019-09-13.
  45. "Debian -- News -- Debian 10 "buster" released". debian.org. Retrieved 2019-08-09.
  46. "Debian -- News -- Debian 8 Long Term Support reaching end-of-life". debian.org. Retrieved 2021-02-15.
  47. "DistroWatch.com: Debian". DistroWatch.com. 2017-10-15. Retrieved 2017-10-15.
  48. "Debian -- Details of package python3 in stretch" . Retrieved 2017-12-19.
  49. "Python in RHEL 8". Red Hat Developer Blog. 2018-11-14. Archived from the original on 2019-05-10. Retrieved 2019-05-10.
  50. "Red Hat Enterprise Linux Life Cycle". Red Hat Customer Portal. Retrieved 2020-04-01.
  51. "DistroWatch.com: Red Hat Enterprise Linux". DistroWatch.com. 2017-09-07. Retrieved 2017-10-15.
  52. "DistroWatch.com: CentOS". DistroWatch.com. 2017-09-14. Retrieved 2017-10-15.
  53. "Release Notes | SUSE Linux Enterprise Desktop/SUSE Linux Enterprise Workstation Extension 15 GA". suse.com. Retrieved 2019-08-08.
  54. 1 2 "DistroWatch.com: openSUSE". DistroWatch.com. 2017-10-14. Retrieved 2017-10-15.
  55. Martelli, Alex (2006). Python in a Nutshell (2nd ed.). O'Reilly. pp. 5–7. ISBN   978-0-596-10046-9.

Further reading