python - How do greenlets work? -
How is implemented? Python uses C stack for interpreter and piles-stack python stack frames, but apart from this, how it allocates / swaps stack, how it hooks into the interpreter and function call mechanism, and this extension How does it interact with? (Any quirks)?
There are some comments on the top of greenlet.c in the source, but they are slightly opaque. FWID I am coming from a perspective of someone who is unfamiliar with CPython internals, but is very familiar with low-level system programming, C, threads, events, corlines / cooperative threads, kernel programming etc.
(Some data points: they and they.)
If found and greenlet If you study, you will see a long commentary on the top of greenlet.c
which starts from 16 line with the following summary ...:
A PyGreenlet There is a range of C stack addresses that should be saved and restored in such a way that whenever we switch in the full range of stacks, there is valid data.
and continue on Line 82, who are asking about you. Do you study these lines (and implement the following 1000+ them; -) ...? I do not see a way to squeeze these 66 lines, while still it does not understand, and no additional value to copy and paste them.
In fact, you will see that there is no real "hooking" in multi-threaded code except for delicate relationships with the thread state, and to save / restore the state of a greenlet The stack is speaking on the stack memcpy
call is "speaking under the nose of the forwarding interpreter") and there are some allocated / re-allocated and empty space to call Python Memory Manager, Or go back to the stack. In line 227-295, three functions handle scruff work, and they are wrapped in "macros" in 298-310 to "make maintenance easier" because the comment has been said.
The interface through which the other extension can interact with the expansion of the green color, has been implemented on 9 56-10445, and the "CObject API" ( greenlet.h
Of course) have been conveyed through the document.
Comments
Post a Comment