[Python-ideas] PEP draft - Composable futures for reactive programming

Guido van Rossum guido at python.org
Sun Dec 22 05:01:26 CET 2013


On Sat, Dec 21, 2013 at 7:53 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sun, Dec 22, 2013 at 2:45 PM, Guido van Rossum <guido at python.org> wrote:
>> To cut through that you'd have to have
>> some kind of stack-swapping coroutine implementation like gevent...
>
> Forgive the stupid question, but how is stack-swapping during blocking
> calls materially different from threads?

It's also known as "green threads". The gevent folks and the Stackless
folks (and a few others) do this and claim it is vastly superior to OS
threads. I believe the main difference is that an OS thread takes up a
relatively large amount of resources in the kernel as well as in user
space (for the stack) while a green thread takes up a comparatively
much smaller amount of space, all in user space -- with the result
that you can have many more green threads than you could have OS
threads, and switching between them will be much faster. The price you
pay is that the kernel doesn't know what you're doing and you have to
intercept all system-call-level I/O to make it non-blocking -- if you
accidentally make a blocking syscall, no other green thread will run.

This may sound like a pure implementation-level distinction, but
implementation is what makes things practical (otherwise we'd all be
using Turing machines or lambda calculus :-).

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list