[Python-ideas] Cofunctions: It's alive! Its alive!

Stefan Behnel stefan_ml at behnel.de
Sun Aug 8 08:50:31 CEST 2010


Ron Adam, 08.08.2010 05:17:
> Would it be even remotely possible...
>
> ... to write a co-function program in a way where it could be switched
> from cooperative multitasking to preemptive multitasking by the use of a
> single flag? (I'd be +10,000 for this.)

I wouldn't.


> If so, it would enable a way to hide a lot of details of multi-tasking
> and multi-processing in a convenient to use api.

Totally not. Cooperative multitasking is about predictable interaction 
between parts of a program. Preemptive multitasking (in the sense of 
threading) is about non-deterministic concurrency. Except for some very 
special cases, there is no way you can take a piece of code that uses 
cooperative multitasking, switch it over to run concurrently, and still 
have it execute safely and correctly.

I may end up liking the idea of using yield statements for thread 
synchronisation points, though.

Stefan




More information about the Python-ideas mailing list