Stackless Python

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.

Stackless Python
Original author(s)Christian Tismer
Developer(s)Anselm Kruis
Initial release1998 (1998)
Stable release
3.7.4-slp, 3.6.9-slp, 2.7.16-slp / August 4, 2019 (2019-08-04)
Preview release
3.8.0b3[1]
Repository
Written inC, Python
Operating systemLinux, Windows
TypeInterpreter
LicensePython Software Foundation License
Websitehttp://www.stackless.com

Design

With Stackless Python, a running program is split into microthreads that are managed by the language interpreter itself, not the operating system kernel—context 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 Python'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.

gollark: Quantum computers can apparently cause problems for all widely deployed asymmetric cryptography via Shor's algorithm.
gollark: It apparently makes brute force take O(sqrt n) time somehow.
gollark: Yes, something something grover's algorithm.
gollark: This is... interesting. I would run it through some sort of automatic formatter tool.
gollark: These are designed to work best on general purpose CPUs - to prevent using dedicated hardware to accelerate bruteforce - and to have a tunable time requirement.

See also

References

  1. The Stackless Python programming language, Stackless Python, 2019-11-14, retrieved 2019-11-14
  2. https://www.youtube.com/watch?v=pDkrkP0yf70
  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.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.