[pypy-dev] coroutine problem

Armin Rigo arigo at tunes.org
Tue Feb 14 17:27:01 CET 2006

Hi Christian,

On Tue, Feb 14, 2006 at 11:55:03AM +0100, Christian Tismer wrote:
>         state.last.frame = yield_current_frame_to_caller()
>         try:
>             thunk.call()

>         try:
>             state.last.frame = yield_current_frame_to_caller()
>             thunk.call()
> I still don't get why you think these are identical.
> It is true, the yield call does never create an exception
> by itself.
> But it is the place where I arrive from any other
> switch, and the switch is built in a way that it
> can create an exception. This pops up exactly
> at the place where we yield.

This is wrong.  The only two ways in which a stack switch occurs in
RPython is by calling a switch() method explicitly, or by returning
a frame object from a function that itself contained a call to
yield_current_frame_to_caller(), like def _bind().

* if RPython code executes an expression 'f.switch()', it means that
  this RPython code is not currently propagating an RPython exception.
  If it were, it would not be executing any expression, it would be busy
  jumping back to immediate callers, or alternatively, busy checking if
  except statements match the current exception.  Even if 'f.switch()'
  is in an except: block, the RPython exception has be caught when the
  switch() is executed, so there is no "current RPython exception" set
  any more.

* if _bind() returns a frame, it will be switched to.  This is if
  _bind() *returns* normally, so no exception.  If, on the other hand,
  _bind() raises an exception without catching it, then it is a fatal
  error condition.  This was all part of the original design of the
  interface in 

   a function that called ``yield_current_frame_to_caller()`` should not
   It would have no implicit parent frame to propagate the exception to.
   That would be a crashingly bad idea.

All this to say that there is no way you can pass an RPython exception
"through" a yield or a switch.

A bientot,


More information about the Pypy-dev mailing list