A Python Implementation That Does Not Use The C Stack
A small advantage is that recursions are no longer limited bythe size of the C stack, but only by the amount of availableheap memory. But that's not the major point.
Stackless Python allows you to run hundreds of thousands of tinytasks, called "tasklets", in a single main thread. These taskletscan run completely decoupled, or they can communicate via "channels".Channels take all the responsibility to control suspension and resumingof tasklets in a very easy-to-manage manner.
Furthermore, the concept of small, communicating tasklets can leadyou to a new, very simple way of formulating your problems.[--much more to be said here--]
Without delving into the (complicated) implementation details,the following is relevant:The Python interpreter is recursive. That is, for every invocationof a Python function or method, another incarnation of theinterpreter is called from C code.By decoupling the execution of Python codefrom the C stack, it is possible to change the order of execution.In particular, this allows to switch between multiple concurrentrunning "threads" of Python code, which are no threads in thesense of the operating system, but so-called "green threads".
Although in alpha state, Stackless is being heavily used by commercialapplications. One outstanding example is the MassiveMultiPlayerOnline Game EVEhttp://www.eve-online.com/ which is completely basedupon Stackless technology.
Oh well!As a measure of efficiency, here a couple of numbers:
With today's most efficient operating system threads on a speciallymodified Linux variant and 1 GB main memory, it is possible torun about 100.000 Threads. The switching rate is somewhere betterthan 1 million per second..
With its tiny Python tasklets, Stackless accomplishes similar performancewithin only 100 MB, but creating a million tasklets.
In conclusion, Stackless Python is very efficient and especially suitedfor simulations with very many autonomous tiny objects.
Stackless is completely compatible with Standard Python, it justadds some functionality. The interpreter is changed internally, but thereis no change of behavior, unless the Stackless features are used.
The Stackless website can be found here:http://www.stackless.com/
[Question copied from Ward's Wiki (seeStacklessPython)]
Is the stackless implementation of continuations better than, for example, a threaded implementation? What implementation does regular Python use?
I want to hear more about what we'll do with all these tasklets.
I am intrigued by the idea of a vast network of reusable components sending messages one to the other.
But it also seems clear to me that, stackless alone will not make this sort of dream a reality: It will require a framework of some point, as well, for the new components to plug into, and to mediate communications.
So I hold two lines of questioning:
--LionKimbro 2006-03-26 18:53:59
Tasklets aside, why isn't the stackless fork of Python accepted as the reference implementatio (CPython)?
--DougRansom 2007-10-10 12:00:00
StacklessPython (last edited 2013-01-29 12:01:44 byMarcAndreLemburg)
Unable to edit the page? See the FrontPage for instructions.