When the python program starts, you have essentially two pieces of code running under the hood.
First, the C code of the CPython interpreter is executed and the standard C-stitch is used to save its internal stack frames. Secondly, the actual python interprets the bytecode, which does not use the C-stack, but uses a bunch to save its stack frames. Gellet is just standard python code and therefore behaves the same.
Now in a typical microflow application, you will have thousands, if not millions, of microtypes (green) that switch all over the place. Each switch is essentially equivalent to calling a deferred return function (so to speak) and thus will use the stack bit. The problem is that the interpreter's C stack will sooner or later hit the stack overflow. This is exactly what the green extension is aimed at; it is designed to move pieces of the stack back and forth to / from the heap to avoid this problem.
As you know, there are three fundamental events with greens, caviar, switch and reset, so let's look at them:
A) spawn
Recently appeared greens are associated with their own base address on the stack (where we are currently). In addition, nothing special happens. The python code of the newly created green dot uses the heap in normal mode, and the interpreter continues to use the C stack as usual.
B) switch
When the green panel switches from the green patch panel, the corresponding part of the C-stack (starting from the base address of the patch panel) is copied to the heap. The copied C-stack area is freed, and the previously saved stack file switches from the heap to the newly freed C-stack area. The python dial-up code continues to use the heap in the usual way. Of course, the extension code keeps track of all of this (which section of the heap matches any rose, etc.).
C) return
The stack is untouched, and the heap area of the returning shard is freed by the python garbage collector.
In essence, this is a lot more details and explanations can be found at ( http://www.stackless.com/pipermail/stackless-dev/2004-March/000022.html ) or simply by reading the code as indicated in Alex's answer.
Rabih Kodeih Jul 03 '13 at 11:57 2013-07-03 11:57
source share