[Twisted-Python] PEP 342 & cooperative threads

Antoine Pitrou solipsis at pitrou.net
Wed Aug 17 11:32:06 EDT 2005


For what it's worth, I started writing a pure Python cooperative threads
package, some weeks ago. It's called "softlets" and uses, of course,
generators. There is a simple scheduler centered around the notion of
"wait objects" - you yield a wait object (e.g. a Queue) and it comes
back when the underlying condition is satisfied (e.g. the Queue has
something to give to you).

I'm writing it for fun but it does have some interesting
- no C extension required, no compiling, no annoying dependency (even
not Twisted actually)
- scalability: you can create thousands of threads with nearly no
overhead, and run them all "at the same time"
- a more comfortable way of writing certain operation sequences than
with cascades of deferreds
- robustness: in contrast to preemptive multithreading, cooperative MT
means you define the synchronisation points explicitly, so you don't
have any resource sharing problems in case you forget some
synchonisation points (latency will be worse, but your program will stay

Although there is no web page currently, you can get the source here (*)
and play with the examples in the examples directory (it's very alpha
and lacks most fonctionality but it does work, and it won't hose your
machine). Nothing is needed except Python 2.4; no setup required, just
checkout the sources.
(*) http://developer.berlios.de/svn/?group_id=4330

Future work would be to add actual useful functionality (timers,
integration with Twisted deferreds, etc.).

Feel free to subscribe to the mailing-list and talk a little ;)
I'm open to feedback, and to people willing to contribute.



Le mercredi 17 août 2005 à 17:02 +0200, tazzo a écrit :
> Hi all,
> referring to the news about the implementation of PEP 342 in python CVS:
> http://dirtsimple.org/2005/08/pep-342-implementation-now-in-cvs.html
> I know that is a great news for asynchronous programming in python and for
> other aspects but I wonder what will be the future of  Twisted, what 
> will change
> (if something will change) in Twisted when PEP 342 will come?
> I think that with PEP 342 we could write a more readable code but does 
> it mean
> rewrite all twisted?
> What is the opinion of  Twisted developers??
> thanks,
> Tazzo

More information about the Twisted-Python mailing list