CPython

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 language.

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 (1994-01-26)
Stable release
3.8.6 / 24 September 2020 (2020-09-24)
Repositoryhttps://github.com/python/cpython
Written inC, Python
Platform42 platforms; see § Distribution
Available inEnglish
TypePython Programming Language Interpreter
LicensePython Software Foundation License
Websitewww.python.org

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 multi-threading scenario is where threads are mostly waiting on external processes to complete.

For example, imagine when three threads are servicing separate clients. One thread may be waiting for a client to reply, 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 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 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;[2] this goal was not met.[3]

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.[4] Unladen Swallow was hosted on Google Code.[5]

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 which got added to the main Python implementation, such as improvements to the cPickle module.[6]

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

The 2009 Q4 development branch was created on 26 January 2010,[11] 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)[3] 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.[12] This merging would have taken some time, since Unladen Swallow was originally based on Python 2.6[13] 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.[14]

Unladen Swallow release history

  • 2009 Q1[15]
  • 2009 Q2[16]
  • 2009 Q3: reduce memory use, improve speed[17]

Distribution

Supported platforms include:[18]

Unix-like
Special and embedded
Other

PEP 11[19] 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:

  • AtheOS (unsupported since 2.6)
  • BeOS (unsupported since 2.6)
  • DOS (unsupported since 2.0)
  • IRIX 4 (unsupported since 2.3)
  • IRIX 5 and later (unsupported since 3.2, 3.7)[20]
  • Mac OS 9 (unsupported since 2.4)
  • MINIX (unsupported since 2.3)
  • VMS (unsupported since 3.3)
  • OS/2 (unsupported since 3.3)
  • RISC OS (unsupported since 3.0)
  • Windows XP (unsupported since 3.5)
  • Windows 2000 (unsupported since 3.3)
  • Windows 3.x (unsupported since 2.0)
  • Windows 9x (unsupported since 2.6)
  • Windows NT4 (unsupported since 2.6)

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.[27] 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 version Distribution end-of-life Python version
Ubuntu 20.04 LTS (Focal Fossa) 2030-04[28] [29] Older version, yet still maintained: 3.8[30]
Ubuntu 18.04 LTS (Bionic Beaver) 2028-04[31] Old version, no longer maintained: 2.7[32] Older version, yet still maintained: 3.6[33]
Ubuntu 16.04 LTS (Xenial Xerus) 2021-04-30 Old version, no longer maintained: 2.7[32] Old version, no longer maintained: 3.5[33]
Debian 10 2024 Old version, no longer maintained: 2.7[34] Older version, yet still maintained: 3.7[35]
Debian 9 2022 Old version, no longer maintained: 2.7[36] Old version, no longer maintained: 3.5[37]
Red Hat Enterprise Linux 8 2029 Old version, no longer maintained: 2.7[38] Older version, yet still maintained: 3.6
Red Hat Enterprise Linux 7 2024-11-30[39] Old version, no longer maintained: 2.7[40]
CentOS 8 2029-05-31 Old version, no longer maintained: 2.7 Older version, yet still maintained: 3.6
CentOS 7 2024-06-30 Old version, no longer maintained: 2.7[41]
SUSE Linux Enterprise Server 15 2031-07-31 Old version, no longer maintained: 2.7[42] Older version, yet still maintained: 3.6
SUSE Linux Enterprise Server 12 2027-10-31 Old version, no longer maintained: 2.7[43]
SUSE Linux Enterprise Server 11 2022-03-31 Old version, no longer maintained: 2.7[44]
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.[45]

References

  1. "Initialization, Finalization, and Threads". Python v3.8.3 documentation. Retrieved 2020-06-04.
  2. Paul, Ryan (2009-03-26). "Ars Technica report on Unladen Swallow goals". Arstechnica.com. Retrieved 2011-08-19.
  3. Winter, Collin; Yasskin, Jeffrey; Kleckner, Reid (2010-03-17). "PEP 3146 - Merging Unladen Swallow into CPython". Python.org.
  4. "People working on Unladen Swallow". Archived from the original on 2015-10-29. Retrieved 2019-08-08.
  5. "Unladen Swallow project page". Retrieved 2011-08-19.
  6. "Issue 9410: Add Unladen Swallow's optimizations to Python 3's pickle. - Python tracker". bugs.python.org. Retrieved 2019-08-08.
  7. "Message on comp.lang.python". Retrieved 2011-08-19.
  8. "Unladen Swallow | Google Groups". Retrieved 2011-08-19.
  9. "reddit post by an Unladen committer". Reddit.com. 2010-06-24. Retrieved 2011-08-19.
  10. Winter, Collin (8 November 2010). "Current status of Unladen-Swallow".
  11. "2009 Q4 release branch creation". 2010-01-26. Retrieved 2011-08-19.
  12. "Developers focus on merge into py3k-jit". 2010-07-13. Retrieved 2011-08-19.
  13. "Unladen Swallow baseline". Python.org. Retrieved 2011-08-19.
  14. Kleckner, Reid (26 March 2011). "Unladen Swallow Retrospective". QINSB is not a Software Blog (qinsb.blogspot.com).
  15. "Unladen Swallow 2009Q1". unladen-swallow, A faster implementation of Python. Retrieved 19 October 2012.
  16. "Unladen Swallow 2009Q2". unladen-swallow, A faster implementation of Python. Retrieved 19 October 2012.
  17. "Unladen Swallow 2009Q3". unladen-swallow, A faster implementation of Python. Retrieved 19 October 2012.
  18. "PythonImplementations". Retrieved 19 July 2012.
  19. "PEP 11 -- Removing support for little used platforms". Python.org. Retrieved 2019-08-08.
  20. "Irix still supported?".
  21. AmigaPython
  22. iSeriesPython
  23. PythonD
  24. http://yellowblue.free.fr/yiki/doku.php/en:dev:python:start Python 2 and 3
  25. Stackless Python for PSP
  26. Python Windows CE port
  27. https://linuxlifecycle.com
  28. "Ubuntu release cycle". Ubuntu. Retrieved 2021-01-18.
  29. "With Python 2 EOL'ed, Ubuntu 20.04 LTS Moves Along With Its Python 2 Removal - Phoronix". www.phoronix.com. Retrieved 2020-04-01.
  30. "Binary package "python3" in ubuntu focal". Launchpad.net.
  31. "Ubuntu 18.04 extended to 2028". ServerWatch.com. 2018-11-15. Retrieved 2019-09-09.
  32. "python-defaults package : Ubuntu". Canonical Ltd. 2018-06-08. Retrieved 2018-06-08.
  33. "python3-defaults package : Ubuntu". Canonical Ltd. 2018-06-08. Retrieved 2018-06-08.
  34. "Debian -- Details of package python in buster". packages.debian.org. Retrieved 2019-09-13.
  35. "Debian -- News -- Debian 10 "buster" released". www.debian.org. Retrieved 2019-08-09.
  36. "DistroWatch.com: Debian". DistroWatch.com. 2017-10-15. Retrieved 2017-10-15.
  37. "Debian -- Details of package python3 in stretch". Retrieved 2017-12-19.
  38. "Python in RHEL 8". Red Hat Developer Blog. 2018-11-14. Retrieved 2019-05-10.
  39. "Red Hat Enterprise Linux Life Cycle". Red Hat Customer Portal. Retrieved 2020-04-01.
  40. "DistroWatch.com: Red Hat Enterprise Linux". DistroWatch.com. 2017-09-07. Retrieved 2017-10-15.
  41. "DistroWatch.com: CentOS". DistroWatch.com. 2017-09-14. Retrieved 2017-10-15.
  42. "Release Notes | SUSE Linux Enterprise Desktop/SUSE Linux Enterprise Workstation Extension 15 GA". www.suse.com. Retrieved 2019-08-08.
  43. "DistroWatch.com: openSUSE". DistroWatch.com. 2017-10-14. Retrieved 2017-10-15.
  44. "DistroWatch.com: openSUSE". DistroWatch.com. 2017-10-14. Retrieved 2017-10-15.
  45. Martelli, Alex (2006). Python in a Nutshell (2nd ed.). O'Reilly. pp. 5–7. ISBN 978-0-596-10046-9.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.