Software:CPython
Original author(s) | Guido van Rossum |
---|---|
Developer(s) | Python core developers and the Python community, supported by the Python Software Foundation |
Initial release | 26 January 1994 |
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 |
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.
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.[1] 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".[2][3]
After several debates, a project was launched in 2023 to propose making the GIL optional from version 3.13 of Python,[4] which is scheduled for release in October 2024.[5]
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;[6] this goal was not met.[7]
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.[8] Unladen Swallow was hosted on Google Code.[9]
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.[10]
In July 2010, some observers speculated on whether the project was dead or dying since the 2009 Q4 milestone had not yet been released.[11] The traffic on Unladen's mailing list had decreased from 500 messages in January 2010 to fewer than 10 in September 2010.[12] It has also been reported that Unladen lost Google's funding.[13] 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."[14]
The 2009 Q4 development branch was created on 26 January 2010,[15] 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)[7] 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.[16] This merging would have taken some time, since Unladen Swallow was originally based on Python 2.6[17] 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.[18]
Unladen Swallow release history
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:[22]
- Unix-like
- Special and embedded
- Other
PEP 11[23] 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.[32] The support status of Python in the table refers to support from the Python core team, and not from the distribution maintainer.
Distribution version | Distribution end-of-life | Python version | |
---|---|---|---|
Ubuntu 22.04 LTS (Jammy Jellyfish) | 3.10 [1] | ||
Ubuntu 20.04 LTS (Focal Fossa) | [33] | ||
Ubuntu 18.04 LTS (Bionic Beaver) | 2.7[34] | 3.6[35] | |
Ubuntu 16.04 LTS (Xenial Xerus) | 2.7[34] | 3.5[35] | |
Debian 12 | 2028-06[36] | ||
Debian 11 | 2026-06[37] | ||
Debian 10 | 2.7[38] | ||
Debian 9 | 2.7[39] | 3.5[40] | |
Red Hat Enterprise Linux 8 | 2.7[41] | 3.6 | |
Red Hat Enterprise Linux 7 | 2024-11-30[42] | 2.7[43] | |
CentOS 8 | 2.7 | 3.6 | |
CentOS 7 | 2.7[44] | ||
SUSE Linux Enterprise Server 15 | 2.7[45] | 3.6 | |
SUSE Linux Enterprise Server 12 | 2.7[46] | ||
SUSE Linux Enterprise Server 11 | 2.7[46] | ||
{{{2}}} |
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.[47]
References
- ↑ "Initialization, Finalization, and Threads". Python v3.8.3 documentation. https://docs.python.org/3/c-api/init.html.
- ↑ Jake Edge (August 15, 2023). "A per-interpreter GIL". LWN. https://lwn.net/Articles/941090/.
- ↑ "PEP 684 – A Per-Interpreter GIL | peps.python.org". https://peps.python.org/pep-0684/.
- ↑ "PEP 703 – Making the Global Interpreter Lock Optional in CPython | peps.python.org" (in en). https://peps.python.org/pep-0703/.
- ↑ "PEP 719 – Python 3.13 Release Schedule | peps.python.org". https://peps.python.org/pep-0719/#schedule.
- ↑ Paul, Ryan (2009-03-26). "Ars Technica report on Unladen Swallow goals". Arstechnica.com. https://arstechnica.com/information-technology/2009/03/google-launches-project-to-boost-python-performance-by-5x/.
- ↑ 7.0 7.1 Winter, Collin; Yasskin, Jeffrey; Kleckner, Reid (2010-03-17). "PEP 3146 - Merging Unladen Swallow into CPython". Python.org. https://peps.python.org/pep-3146/.
- ↑ "People working on Unladen Swallow". https://code.google.com/p/unladen-swallow/people/list.
- ↑ "Unladen Swallow project page". https://code.google.com/p/unladen-swallow/.
- ↑ "Issue 9410: Add Unladen Swallow's optimizations to Python 3's pickle. - Python tracker". https://bugs.python.org/issue9410.
- ↑ "Message on comp.lang.python". https://groups.google.com/g/comp.lang.python/c/afhcrbQkodQ?pli=1#bdf73a28f3f770cb.
- ↑ "Unladen Swallow | Google Groups". https://groups.google.com/g/unladen-swallow/about.
- ↑ "reddit post by an Unladen committer". Reddit.com. 2010-06-24. https://www.reddit.com/r/Python/comments/cilk0/comment/c0su1wt/.
- ↑ Winter, Collin (8 November 2010). "Current status of Unladen-Swallow". https://groups.google.com/g/unladen-swallow/c/8gERKcRBTQQ/m/KiUjXJNvTr0J.
- ↑ "2009 Q4 release branch creation". 2010-01-26. https://code.google.com/p/unladen-swallow/source/detail?spec=svn1164&r=1042.
- ↑ "Developers focus on merge into py3k-jit". 2010-07-13. https://groups.google.com/g/unladen-swallow/c/vj0iYHnEV7E.
- ↑ "Unladen Swallow baseline". Python.org. https://peps.python.org/pep-3146/#rationale-implementation.
- ↑ Kleckner, Reid (26 March 2011). "Unladen Swallow Retrospective". https://qinsb.blogspot.com/2011/03/unladen-swallow-retrospective.html.
- ↑ "Unladen Swallow 2009Q1". unladen-swallow, A faster implementation of Python. https://code.google.com/p/unladen-swallow/wiki/Release2009Q1.
- ↑ "Unladen Swallow 2009Q2". unladen-swallow, A faster implementation of Python. https://code.google.com/p/unladen-swallow/wiki/Release2009Q2.
- ↑ "Unladen Swallow 2009Q3". unladen-swallow, A faster implementation of Python. https://code.google.com/p/unladen-swallow/wiki/Release2009Q3.
- ↑ "PythonImplementations". https://wiki.python.org/moin/PythonImplementations.
- ↑ "PEP 11 -- Removing support for little used platforms". https://peps.python.org/pep-0011/.
- ↑ "Irix still supported?". 14 February 2009. https://mail.python.org/pipermail/python-dev/2009-February/086111.html.
- ↑ AmigaPython
- ↑ iSeriesPython
- ↑ PythonD
- ↑ http://yellowblue.free.fr/yiki/doku.php/en:dev:python:start Python 2 and 3
- ↑ Stackless Python for PSP
- ↑ Python Windows CE port
- ↑ "Python". https://vmssoftware.com/products/python/.
- ↑ "Support Life Cycles for Enterprise Linux Distributions". https://linuxlifecycle.com/.
- ↑ "With Python 2 EOL'ed, Ubuntu 20.04 LTS Moves Along With Its Python 2 Removal - Phoronix". https://www.phoronix.com/news/Python-2-EOL-Ubuntu-20.04.
- ↑ 34.0 34.1 "python-defaults package: Ubuntu". Canonical Ltd.. 2018-06-08. https://launchpad.net/ubuntu/+source/python-defaults.
- ↑ 35.0 35.1 "python3-defaults package: Ubuntu". Canonical Ltd.. 2018-06-08. https://launchpad.net/ubuntu/+source/python3-defaults.
- ↑ "Debian 12 bookworm released". https://www.debian.org/News/2023/20230610.
- ↑ "Debian -- News -- Debian 11 "bullseye" released". https://www.debian.org/News/2021/20210814.en.html.
- ↑ "Debian -- Details of package python in buster". https://packages.debian.org/buster/python.
- ↑ "DistroWatch.com: Debian". DistroWatch.com. 2017-10-15. https://distrowatch.com/table.php?distribution=debian.
- ↑ "Debian -- Details of package python3 in stretch". https://packages.debian.org/stretch/python3.
- ↑ "Python in RHEL 8" (in en-US). 2018-11-14. https://developers.redhat.com/blog/2018/11/14/python-in-rhel-8/.
- ↑ "Red Hat Enterprise Linux Life Cycle". https://access.redhat.com/support/policy/updates/errata.
- ↑ "DistroWatch.com: Red Hat Enterprise Linux". DistroWatch.com. 2017-09-07. https://distrowatch.com/table.php?distribution=redhat.
- ↑ "DistroWatch.com: CentOS". DistroWatch.com. 2017-09-14. https://distrowatch.com/table.php?distribution=centos.
- ↑ "Release Notes | SUSE Linux Enterprise Desktop/SUSE Linux Enterprise Workstation Extension 15 GA". https://www.suse.com/releasenotes/x86_64/SUSE-SLED/15/index.html#Features.Other.
- ↑ 46.0 46.1 "DistroWatch.com: openSUSE". DistroWatch.com. 2017-10-14. https://distrowatch.com/table.php?distribution=opensuse.
- ↑ Martelli, Alex (2006). Python in a Nutshell (2nd ed.). O'Reilly. pp. 5–7. ISBN 978-0-596-10046-9.
Further reading
- Shaw, Anthony (2021). CPython Internals: Your Guide to the Python 3 Interpreter. Real Python. ISBN 9781775093343.
External links
- on GitHub
- Downloads: https://www.python.org/downloads/
Original source: https://en.wikipedia.org/wiki/CPython.
Read more |