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 ma ...
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
microthread Microthreads are functions that may run in parallel to gain increased performance in microprocessors. They provide an execution model that uses a few additional instructions in a conventional processor to break code down into fragments that execut ...
s, 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 Channel, channels, channeling, etc., may refer to: Geography * Channel (geography), in physical geography, a landform consisting of the outline (banks) of the path of a narrow body of water. Australia * Channel Country, region of outback Austral ...
, 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 learnin ...
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 processes ...
ing and
task scheduling In computing, scheduling is the action of assigning ''resources'' to perform ''tasks''. The ''resources'' may be processors, network links or expansion cards. The ''tasks'' may be threads, processes or data flows. The scheduling activity is c ...
is done purely in the interpreter (these are thus also regarded as a form of
green thread In computer programming, a green thread is a thread that is scheduled by a runtime library or virtual machine (VM) instead of natively by the underlying operating system (OS). Green threads emulate multithreaded environments without relying on an ...
). 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 * E ...
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 vir ...
. 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 CPytho ...
, a self-hosting Python interpreter and
JIT compiler In computing, just-in-time (JIT) compilation (also dynamic translation or run-time compilations) is a way of executing computer code that involves compilation during execution of a program (at run time) rather than before execution. This may cons ...
.


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), Python programming language. Written in C (programming language), C and Python, CPython is the default and most widely used implementation of the Python language. CP ...
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 Asynchrony (computer programming), asynchronous, non-blocking I/O, non-blocking Subroutine, function to be structured in a way simi ...
/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 profess ...
'' massively multiplayer online game as well as in
IronPort IronPort Systems, Inc., headquartered in San Bruno, California, was a company that designed and sold products and services that were intended to protect enterprises against internet threats. IronPort was founded in December 2000 by Scott Banist ...
'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 runtime ...
*
Limbo (programming language) Limbo is a programming language for writing distributed systems and is the language used to write applications for the Inferno operating system. It was designed at Bell Labs by Sean Dorward, Phil Winterbottom, and Rob Pike. The Limbo compile ...
*
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 co ...
*
SCOOP (software) SCOOP (Simple Concurrent Object Oriented Programming) is a concurrency model designed for the Eiffel programming language, conceived by Eiffel's creator and designer, Bertrand Meyer. SCOOP defines a way for an object oriented program to be writte ...


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