Jump to content

Stackless Python: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Design: formatting fixes
m formatting fixes
Line 28: Line 28:
}}
}}


'''Stackless Python''', or '''Stackless''', is a [[Python (programming language)|Python programming language]] interpreter, so named because it avoids depending on the [[C (programming language)|C]] [[call stack]] for its own stack. In practice, Stackless Python uses the C stack, but the stack is cleared between function calls.<ref>Archived at [https://ghostarchive.org/varchive/youtube/20211211/pDkrkP0yf70 Ghostarchive]{{cbignore}} and the [https://web.archive.org/web/20140103062231/http://www.youtube.com/watch?v=pDkrkP0yf70 Wayback Machine]{{cbignore}}: {{cite AV media| url = https://www.youtube.com/watch?v=pDkrkP0yf70| title = The story of stackless Python | website=[[YouTube]]}}{{cbignore}}</ref> The most prominent feature of Stackless is [[microthread]]s, which avoid much of the overhead associated with usual operating system [[Thread (computer science)|thread]]s. In addition to Python features, Stackless also adds support for [[coroutine]]s, communication [[channel (programming)|channels]], and task [[serialization]].
'''Stackless Python''', or '''Stackless''', is a [[Python (programming language)|Python programming language]] interpreter, so named because it avoids depending on the [[C (programming language)|C]] [[call stack]] for its own stack. In practice, Stackless Python uses the C stack, but the stack is cleared between function calls.<ref>Archived at [https://ghostarchive.org/varchive/youtube/20211211/pDkrkP0yf70 Ghostarchive]{{cbignore}} and the [https://web.archive.org/web/20140103062231/http://www.youtube.com/watch?v=pDkrkP0yf70 Wayback Machine]{{cbignore}}: {{cite AV media| url = https://www.youtube.com/watch?v=pDkrkP0yf70| title = The story of stackless Python | website=[[YouTube]]}}{{cbignore}}</ref> The most prominent feature of Stackless is [[microthread]]s, which avoid much of the overhead associated with usual operating system [[Thread (computing)|threads]]. In addition to Python features, Stackless also adds support for [[coroutine]]s, communication [[channel (programming)|channels]], and task [[serialization]].


==Design==
==Design==
Line 35: Line 35:
Although microthreads make it easier to deal with running subtasks on a single core, Stackless Python does not remove CPython's [[Global Interpreter Lock]], nor does it use multiple threads and/or processes. So it allows only [[cooperative multitasking]] on a shared CPU and not [[parallel computing|parallelism]] (preemption was originally not available but is now in some form<ref>{{cite web |url=https://bitbucket.org/stackless-dev/stackless/wiki/Home |title=About Stackless |quote=a round robin scheduler is built in. It can be used to schedule tasklets either cooperatively or preemptively. |accessdate=26 August 2016}}</ref>). To use multiple CPU cores, one would still need to build an interprocess communication system on top of Stackless Python processes.
Although microthreads make it easier to deal with running subtasks on a single core, Stackless Python does not remove CPython's [[Global Interpreter Lock]], nor does it use multiple threads and/or processes. So it allows only [[cooperative multitasking]] on a shared CPU and not [[parallel computing|parallelism]] (preemption was originally not available but is now in some form<ref>{{cite web |url=https://bitbucket.org/stackless-dev/stackless/wiki/Home |title=About Stackless |quote=a round robin scheduler is built in. It can be used to schedule tasklets either cooperatively or preemptively. |accessdate=26 August 2016}}</ref>). To use multiple CPU cores, one would still need to build an interprocess communication system on top of Stackless Python processes.


Due to the considerable number of changes in the source, Stackless Python cannot be installed on a preexisting Python installation as an [[Software extension|extension]] or [[library (computer science)|library]]. It is instead a complete Python distribution in itself. The majority of Stackless's features have also been implemented in [[PyPy]], a [[Self-hosting (compilers)|self-hosting]] Python interpreter and [[Just-in-time compilation|JIT compiler]].<ref>{{cite web|url=http://pypy.readthedocs.org/en/latest/stackless.html|title=Application-level Stackless features — PyPy documentation|website=pypy.readthedocs.org}}</ref>
Due to the considerable number of changes in the source, Stackless Python cannot be installed on a preexisting Python installation as an [[Plug-in (computing)|extension]] or [[library (computing)|library]]. It is instead a complete Python distribution in itself. The majority of Stackless's features have also been implemented in [[PyPy]], a [[Self-hosting (compilers)|self-hosting]] Python interpreter and [[Just-in-time compilation|JIT compiler]].<ref>{{cite web|url=http://pypy.readthedocs.org/en/latest/stackless.html|title=Application-level Stackless features — PyPy documentation|website=pypy.readthedocs.org}}</ref>


==Use==
==Use==
Although the whole Stackless is a separate distribution, its switching functionality has been successfully packaged as a [[CPython]] extension called greenlet.<ref>{{cite web|url=http://greenlet.readthedocs.org/en/latest/|title=greenlet: Lightweight concurrent programming — greenlet 0.4.0 documentation|website=greenlet.readthedocs.org}}</ref> It is used by a number of libraries (e.g. gevent<ref>{{cite web|url=http://www.gevent.org|title=What is gevent? — gevent 1.3.0.dev0 documentation|website=www.gevent.org}}</ref>) to provide a [[Green threads|green threading]] solution for CPython. Python since has received a native solution for green threads: [[await]]/async.
Although the whole Stackless is a separate distribution, its switching functionality has been successfully packaged as a [[CPython]] extension called greenlet.<ref>{{cite web|url=http://greenlet.readthedocs.org/en/latest/|title=greenlet: Lightweight concurrent programming — greenlet 0.4.0 documentation|website=greenlet.readthedocs.org}}</ref> It is used by a number of libraries (e.g. gevent<ref>{{cite web|url=http://www.gevent.org|title=What is gevent? — gevent 1.3.0.dev0 documentation|website=www.gevent.org}}</ref>) to provide a [[Green thread|green threading]] solution for CPython. Python since has received a native solution for green threads: [[Async/await|await]]/async.


Stackless is used extensively in the implementation of the ''[[Eve Online]]'' massively multiplayer online game as well as in [[IronPort]]'s mail platform.
Stackless is used extensively in the implementation of the ''[[Eve Online]]'' massively multiplayer online game as well as in [[IronPort]]'s mail platform.

Revision as of 02:11, 11 March 2023

Stackless Python
Original author(s)Christian Tismer
Developer(s)Anselm Kruis
Initial release1998; 27 years ago (1998)
Stable release
3.8.1-slp[1] Edit this on Wikidata / January 22, 2020; 5 years ago (2020-01-22)
Preview release
12 August 2021; 3 years ago (12 August 2021)
Repository
Written inC, Python
Operating systemLinux, macOS, Windows
TypeInterpreter
LicensePython Software Foundation License
Websitewww.stackless.com

Stackless Python, or Stackless, is a Python programming language interpreter, so named because it avoids depending on the C call stack for its own stack. In practice, Stackless Python uses the C stack, but the stack is cleared between function calls.[2] The most prominent feature of Stackless is microthreads, which avoid much of the overhead associated with usual operating system threads. In addition to Python features, Stackless also adds support for coroutines, communication channels, and task serialization.

Design

With Stackless Python, a running program is split into microthreads that are managed by the language interpreter itself, not the operating system kernelcontext switching and task scheduling is done purely in the interpreter (these are thus also regarded as a form of green thread). Microthreads manage the execution of different subtasks in a program on the same CPU core. Thus, they are an alternative to event-based asynchronous programming and also avoid the overhead of using separate threads for single-core programs (because no mode switching between user mode and kernel mode needs to be done, so CPU usage can be reduced).

Although microthreads make it easier to deal with running subtasks on a single core, Stackless Python does not remove CPython's Global Interpreter Lock, nor does it use multiple threads and/or processes. So it allows only cooperative multitasking on a shared CPU and not parallelism (preemption was originally not available but is now in some form[3]). To use multiple CPU cores, one would still need to build an interprocess communication system on top of Stackless Python processes.

Due to the considerable number of changes in the source, Stackless Python cannot be installed on a preexisting Python installation as an extension or library. It is instead a complete Python distribution in itself. The majority of Stackless's features have also been implemented in PyPy, a self-hosting Python interpreter and JIT compiler.[4]

Use

Although the whole Stackless is a separate distribution, its switching functionality has been successfully packaged as a CPython extension called greenlet.[5] It is used by a number of libraries (e.g. gevent[6]) to provide a green threading solution for CPython. Python since has received a native solution for green threads: await/async.

Stackless is used extensively in the implementation of the Eve Online massively multiplayer online game as well as in IronPort's mail platform.

See also

References

  1. ^ "Release v3.8.1-slp". 12 August 2021. Retrieved 8 March 2022.
  2. ^ Archived at Ghostarchive and the Wayback Machine: The story of stackless Python. YouTube.
  3. ^ "About Stackless". Retrieved 26 August 2016. a round robin scheduler is built in. It can be used to schedule tasklets either cooperatively or preemptively.
  4. ^ "Application-level Stackless features — PyPy documentation". pypy.readthedocs.org.
  5. ^ "greenlet: Lightweight concurrent programming — greenlet 0.4.0 documentation". greenlet.readthedocs.org.
  6. ^ "What is gevent? — gevent 1.3.0.dev0 documentation". www.gevent.org.