Stackless Python
   HOME

TheInfoList



OR:

Stackless Python, or Stackless, is a
Python programming language Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically-typed and garbage-collected. It supports multiple programming p ...
interpreter, so named because it avoids depending on the C
call stack In computer science, a call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, program stack, control stack, run-time stack, or mac ...
for its own stack. In practice, Stackless Python uses the C stack, but the stack is cleared between function calls. 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
coroutine Coroutines are computer program components that generalize subroutines for non-preemptive multitasking, by allowing execution to be suspended and resumed. Coroutines are well-suited for implementing familiar program components such as cooperative ...
s, communication channels, and task
serialization In computing, serialization (or serialisation) is the process of translating a data structure or object state into a format that can be stored (e.g. files in secondary storage devices, data buffers in primary storage devices) or transmitted (e ...
.


Design

With Stackless Python, a running program is split into microthreads that are managed by the language interpreter itself, not the operating system
kernel Kernel may refer to: Computing * Kernel (operating system), the central component of most operating systems * Kernel (image processing), a matrix used for image convolution * Compute kernel, in GPGPU programming * Kernel method, in machine learn ...
context switch In computing, a context switch is the process of storing the state of a process or thread, so that it can be restored and resume execution at a later point, and then restoring a different, previously saved, state. This allows multiple processe ...
ing 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 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 (per process) can execute at a time. An interpreter that uses GIL always allows exactly o ...
, nor does it use multiple threads and/or processes. So it allows only
cooperative multitasking Cooperative multitasking, also known as non-preemptive multitasking, is a style of computer multitasking in which the operating system never initiates a context switch from a running process to another process. Instead, in order to run multiple ...
on a shared CPU and not parallelism (preemption was originally not available but is now in some form). 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 Extension, extend or extended may refer to: Mathematics Logic or set theory * Axiom of extensionality * Extensible cardinal * Extension (model theory) * Extension (predicate logic), the set of tuples of values that satisfy the predicate * Ext ...
or
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
. It is instead a complete Python distribution in itself. The majority of Stackless's features have also been implemented in
PyPy 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 CPyth ...
, a self-hosting Python interpreter and JIT compiler.


Use

Although the whole Stackless is a separate distribution, its switching functionality has been successfully packaged as a
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 Python language. CPython can be defined as both an interpreter and a compi ...
extension called greenlet. It is used by a number of libraries (e.g. gevent) to provide a green threading solution for CPython. Python since has received a native solution for green threads:
await In computer programming, the async/await pattern is a syntactic feature of many programming languages that allows an asynchronous, non-blocking function to be structured in a way similar to an ordinary synchronous function. It is semantically rel ...
/async. Stackless is used extensively in the implementation of the ''
Eve Online ''Eve Online'' (stylised ''EVE Online'') is a space-based, persistent world massively multiplayer online role-playing game (MMORPG) developed and published by CCP Games. Players of ''Eve Online'' can participate in a number of in-game profes ...
'' massively multiplayer online game as well as in IronPort's mail platform.


See also

*
Erlang (programming language) Erlang ( ) is a general-purpose, concurrent, functional programming language, and a garbage-collected runtime system. The term Erlang is used interchangeably with Erlang/OTP, or Open Telecom Platform (OTP), which consists of the Erlang run ...
* Limbo (programming language) *
Go (programming language) Go is a statically typed, compiled programming language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It is syntactically similar to C, but with memory safety, garbage collection, structural typing, and CSP-style ...
* SCOOP (software)


References


External links

* * Stackless Python Documentation for
3.7-slp
*
Multithreaded Game Scripting with Stackless Python
by Harry Kalogirou

by Christian Tismer {{Python (programming language) Concurrent computing Python (programming language) implementations Software using the PSF license