Mailing List Archive

continuations for the curious
Howdy,

my modules are nearly ready. I will be out of my office
for two weeks, but had no time to finalize and publish yet.
Stackless Python has reached what I wanted it to reach:
A continuation can be saved at every opcode.

The continuationmodule has been shrunk heavily.
Some extension is still needed, continuations
are still frames, but they can be picked like
Sam wanted it originally.

Sam, I'm pretty sure this is more than enough for
coroutines. Just have a look at getpcc(), this is
now very easy. All involved frames are armed so that
they *can* save themselves, but will do so just if
necessary. The cheapest solution I could think of,
no other optimization is necessary. If your coroutine
functions like to swap two frames, and if they manage to
do so that the refcount of the target stays at one,
no extra frame will be generated.
That's it, really.

If someone wants to play, get the stackless module, replace
ceval.c, and build continuationmodule.c as a dll or whatever.

testct.py contains a lot of crap. The first implementation
of class coroutine is working right.
The second one is wrong by concept.

later - chris

ftp://ftp.pns.cc/pub/veryfar.zip

--
Christian Tismer :^) <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.python.net
10553 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
we're tired of banana software - shipped green, ripens at home
continuations for the curious [ In reply to ]
Hey Chris, I think you're missing some include files
from 'veryfar.zip'?

ceval.c: In function `PyEval_EvalCode':
ceval.c:355: warning: return makes pointer from integer without a cast
ceval.c: In function `PyEval_EvalCode_nr':
ceval.c:375: `Py_UnwindToken' undeclared (first use this function)
ceval.c:375: (Each undeclared identifier is reported only once
ceval.c:375: for each function it appears in.)
ceval.c: In function `eval_code2_setup':
ceval.c:490: structure has no member named `f_execute'
ceval.c:639: structure has no member named `f_first_instr'
ceval.c:640: structure has no member named `f_next_instr'

-Sam
continuations for the curious [ In reply to ]
I've been playing for a bit, trying to write my own coroutine class
(obeying the law of "you won't understand it until you write it
yourself") based on one I've worked up for 'lunacy'.

I think I have it, let me know what you think:

>>> from coroutine import *
>>> cc = coroutine (counter, 100, 10)
>>> cc.resume()
100
>>> cc.resume()
110
>>>

Differences:
1) callcc wraps the 'escape frame' with a lambda, so that
it can be invoked like any other function. this actually
simplifies the bootstrapping, because starting the function
is identical to resuming it.

2) the coroutine object keeps track of who resumed it, so that
it can resume the caller without having to know who it is.

3) the coroutine class keeps track of which is the currently
'active' coroutine. It's currently a class variable, but
I think this can lead to leaks, so it might have to be made
a global.

+-----------------------------------------------------------------
| For those folks (like me) that were confused about where to get
| all the necessary files for building the latest Stackless Python,
| here's the procedure:
|
| 1) unwrap a fresh copy of 1.5.2
| 2) unzip
| http://www.pns.cc/anonftp/pub/stackless_990713.zip
| on top of it
| 3) then, unzip
| ftp://ftp.pns.cc/pub/veryfar.zip
| on top of that
| 4) add "continuation continuationmodule.c" to Modules/Setup

-Sam
Re: continuations for the curious [ In reply to ]
Sam Rushing wrote:
>
> +-----------------------------------------------------------------
> | For those folks (like me) that were confused about where to get
> | all the necessary files for building the latest Stackless Python,
> | here's the procedure:

Thanks... this guide made me actually try it ;-)

> |
> | 1) unwrap a fresh copy of 1.5.2
> | 2) unzip
> | http://www.pns.cc/anonftp/pub/stackless_990713.zip
> | on top of it
> | 3) then, unzip
> | ftp://ftp.pns.cc/pub/veryfar.zip
> | on top of that

It seems that Christian forgot the directory information in this ZIP
file. You have to move the continuationmodule.c file to Modules/
by hand.

> | 4) add "continuation continuationmodule.c" to Modules/Setup

--
Marc-Andre Lemburg
______________________________________________________________________
Y2000: 157 days left
Business: http://www.lemburg.com/
Python Pages: http://www.lemburg.com/python/