Stackless Python and Python 2.x

Paul Rubin phr-n2001 at nightsong.com
Mon Sep 3 18:17:14 EDT 2001


"Tim Peters" <tim.one at home.com> writes:
> It doesn't matter.  Paul asked how generators can be implemented short of
> full-blown coroutines or continuations.  The text I pointed him to showed
> one way it can be done using a single stack.  If he's willing to accept
> continuations as an implementation technique, the ways in which the
> referenced technique run afoul of standard C are trivial by comparison.  C
> isn't the point here; "single stack" is.

OK, I got your response and read PEP 252.  It's impressive.  But now
I'm wondering from the opposite end.  If the regular Python
implementation puts function call frames on the heap, then what's
the difference between regular Python and Stackless Python?

I also noticed somewhere that the compiler does something special if
it sees a yield statement in a block.  What happens if something evals
to a yield statement?  Worse, what happens if there's a finally clause:

  x = "yield blah()"

  try: 
    exec x
  finally:
    mumble()

The only way out that I can see is for the yield statement to be able
to fail.  Executing a yield would check for the presence of a pending
finally: clause, and throw an exception (InvalidYield or whatever) if
there's a finally: present.  Maybe this is already how it works, but
PEP 252 didn't spell that out.



More information about the Python-list mailing list