|
In my quest to do the most stupid and outright silly things possible with Python, I dived into the problem of continuations. This was triggered by me playing with Seaside2 for Smalltalk, a rather cool web framework that makes heavy use of continuations.
So I checked what options I have for continuations in Python. Looks like I am out in the colde - the Stackless guy dropped continuations in his work and concentrates on micro threads and stuff like that. Normal CPython doesn't have anything resembling continuations at all.
But what are threads actually other than just special forms of continuations? You can build threads, coroutines, exception handling, generators and stuff like that with continuations - can we do it the other way around, too?
In fact, yes, we can. Kind of. The result is linked under the title. I make use of the Greenlets module for this so you can't run it directly in standard CPython - you have to install the Greenlets. But they work with standard CPython 2.3 and are available for many platforms, so maybe you can give it a try.
I could even hack something like this with the normal threads and locks - it would be rather clumsy, but should be doable. But it would make the source more complicated, so for now I stay with Greenlets.
|