Jump to content

Stackless Python

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by KAtremer (talk | contribs) at 08:10, 7 February 2014 (→‎Design). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Stackless Python
Original author(s)Christian Tismer
Repository
Written inC, Python
Operating systemLinux, Mac OS X, 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. 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 allow to manage execution of different subtasks in a program on a 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 allow to easier deal with running subtasks on a single core, Stackless Python neither removes Python's global interpreter lock nor utilises multiple threads and/or processes. So it allows only cooperative multitasking on a shared CPU and not true concurrency. To utilise 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.[citation needed]

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 to provide for concurrency,[1] as well as in IronPort's mail platform. Second Life is also beginning to use it.[2]

See also

References

  1. ^ Combs, Nate (2005-10-14). "Nested Worlds". Terra Nova. {{cite web}}: Italic or bold markup not allowed in: |publisher= (help)
  2. ^ "Eventlet". Second Life Wiki. Retrieved 2008-03-16.