Stackless Python
Original author(s) | Christian Tismer |
---|---|
Written in | C, Python |
Operating system | Linux, Mac OS X, Windows |
Type | Interpreter |
License | Python Software Foundation License |
Website |
www |
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. 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 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 neither removes Python's Global Interpreter Lock nor uses multiple threads and/or processes. So it allows only cooperative multitasking on a shared CPU and not parallelism (preemption wasn't available but is now in some form[1]). To use multiple CPU cores, one would still need to build an interprocess communication 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.[2]
Use
Although the whole Stackless is a separate distribution, its switching functionality has been successfully packaged as a CPython extension called greenlet. It is used by a number of libraries (e.g. gevent) to provide a "green threading" solution for CPython.
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
- Erlang (programming language)
- Limbo (programming language)
- Go (programming language)
- SCOOP (software)
References
- ↑ "About Stackless". Retrieved 26 August 2016.
a round robin scheduler is built in. It can be used to schedule tasklets either cooperatively or preemptively.
- ↑ http://pypy.readthedocs.org/en/latest/stackless.html
External links
- Official website
- Multithreaded Game Scripting with Stackless Python by Harry Kalogirou
- Continuations and Stackless Python by Christian Tismer