[Stackless] gevent

Richard Tew richard.m.tew at gmail.com
Fri Nov 13 19:43:58 CET 2009


On Thu, Nov 12, 2009 at 5:54 PM, Denis Bilenko <denis.bilenko at gmail.com> wrote:
> On Thu, Nov 12, 2009 at 1:46 AM, Richard Tew <richard.m.tew at gmail.com> wrote:
>> Interesting, one of the many libraries based on the Greenlet spinoff
>> extension seems to have already done this.
>>
>> gevent: http://gevent.org/
>>
>> gevent monkey patching: http://gevent.org/gevent.monkey.html
>>
>
> I've actually been wondering for some time now whether I should add
> support for stackless to gevent and how to do it.

It would certainly benefit Stackless, as People would of course be
able to use wide swathes of the standard library and have their
tasklets block nicely.

> There are a couple of things I don't quite understand though.
>
> 1. Will gevent on stackless take advantage of faster "soft" switching?
>
> From reading this explanation by Kristján Valur Jónsson
>
>  > 'hard switching' occurs when it becomes necessary to save the C
> stack, and manipulate the stack pointer.
>  > Usually this is because some C code has been involved in the
> tasklet, so that its state cannot be fully
>  > represented by just a linked chain of python frames.  For example,
> if python code calls some C function
>  > which then recursively calls into python.
>  http://www.stackless.com/pipermail/stackless/2009-September/004271.html
>
> it seems that it will not. That is because all switching is
> orchestrated by the libevent event loop which is C code.

I looked for the event loop the other day, but couldn't find it, can
you give me a pointer to it?

> 2. Are other features of stackless (e.g. tasklet pickling) going to
> work in such arrangement?

Pickling will work as good as it ever does.  IIRC if you are going to
pickle a tasklet, you need to have a fair idea it is safe to do so.
This includes what will be dragged in and pickled with it, what it is
currently blocked on and what is in the call stack (no calls to C
extensions and then back into Python).

> 3. Is it possible to do switching directly in Stackless, in a manner
> similar to greenlet's switch() and throw() methods?
> I guess I could emulate greenlet's interface with Tasklet + Channel,
> but that seems like an overkill.

I am not sure what you need.  Can you give some context where you do
this with greenlet?

Cheers,
Richard.




More information about the Stackless mailing list