[Python-Dev] 'stackless' python?

Christian Tismer tismer at appliedbiometrics.com
Mon May 17 09:07:22 CEST 1999


Tim Peters wrote:

[to Sam]

> The other point being that you want to avoid "inside out" logic, though,
> right?  Earlier you posted a kind of ideal:
> 
>     Recently I've written an async server that needed to talk to several
>     other RPC servers, and a mysql server.  Pseudo-example, with
>     possibly-async calls in UPPERCASE:
> 
>       auth, archive = db.FETCH_USER_INFO (user)
>       if verify_login(user,auth):
>           rpc_server = self.archive_servers[archive]
>           group_info = rpc_server.FETCH_GROUP_INFO (group)
>           if valid (group_info):
>               return rpc_server.FETCH_MESSAGE (message_number)
>           else:
>               ...
>           else:
>               ...
> 
> I assume you want to capture a continuation object in the UPPERCASE methods,
> store it away somewhere, run off to your select/poll/whatever loop, and have
> it invoke the stored continuation objects as the data they're waiting for
> arrives.
> 
> If so, that's got to be the nicest use for continuations I've seen!  All
> invisible to the end user.  I don't know how to fake it pleasantly without
> threads, either, and understand that threads aren't appropriate for resource
> reasons.  So I don't have a nice alternative.

It can always be done with threads, but also without. Tried it
last night, with proper refcounting, and it wasn't too easy
since I had to duplicate the Python frame chain.

...

> Suppose the driver were in a script instead:
> 
> thing(5)           # line 1
> print repr(saved)  # line 2
> saved.throw(0)     # line 3
> saved.throw(0)     # line 4
> 
> Then the continuation would (eventually) "return to" the "print repr(saved)"
> and we'd get an infinite output tail of:
> 
> Continuation object at 80d30d0>
> n== 2
> n== 1
> n== 0
> Done!
> Continuation object at 80d30d0>
> n== 2
> n== 1
> n== 0
> Done!

This is at the moment exactly what happens, with the difference that
after some repetitions we GPF due to dangling references
to too often decref'ed objects. My incref'ing prepares for
just one re-incarnation and should prevend a second call.
But this will be solved, soon.

> and never reach line 4.  Right?  That's the part that Guido hates <wink>.

Yup. With a little counting, it was easy to survive:

def main():
    global a
    a=2
    thing (5)
    a=a-1
    if a:
        saved.throw (0)

Weird enough and needs a much better interface.
But finally I'm quite happy that it worked so smoothly
after just a couple of hours (well, about six :)

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at 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




More information about the Python-Dev mailing list