Making sense of Stackless
Christian Tismer
tismer at tismer.com
Sun Feb 27 15:33:05 EST 2000
Darrell wrote:
>
> Thinking about how I could use Stackless and how it's different from using
> callbacks on a object. I decided to view continuations as objects and here's
> were it lead.
>
> If an instance can be thought of as a stack frame then a continuation can be
> thought of as an instance with a constructor and a run method.
>
> import continuation
>
> def construct():
> tripFlag=1
> c=continuation.caller()
> tf=c.update(tripFlag)
> if tripFlag==1:
> # Don't understand how tripFlag stops being equal to 1
> return c
> return tripFlag
What do you want to achieve with the update() ?
The value just passes through. update is used to
either update a co in *your* frame to that
assignment position, or to update a different
frame's co to that frame's current true state.
Both don't seem to apply here since your caller()
has not changed its state.
I guess you can leave that out.
It is a bit hard to use just a single function for both
initialisation and the action. I don't see an easy way
to avoid the "if someinit" stuff.
Well, here the same as a single function:
def classFunc():
print 'Construct:'
x=1
y=2
c=continuation.current()
if c != None:
return c
print 'Run:'
x=x+1
print x+y
This has the same effect as your construct() call.
current() is the same as caller(0), btw.
What happens here?
At the "c=" position, we have a snapshot. We return this
snapshot. When you call this continuation later, you
are repeating this assignment, but this time you are
implicitly passing None. A good thing, since this
auto-clears the otherwise cyclic reference!
Well, it would be a speed improvement if we could save that
if part. You could try a c.update(), but this doesn't work
since c is dead already. Maybe I should provide a method
update_release() that does the same thing, but also
frees the connection? Note that this would combine
update() and deleting co.link into one step.
cheers - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaunstr. 26 : *Starship* http://starship.python.net
14163 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
More information about the Python-list
mailing list