Freeze and Resume execution

Peter Hansen peter at engcorp.com
Thu May 20 09:10:40 EDT 2004


Miki Tebeka wrote:

> I'm looking for a way to "yield" an exception.
> 
> Background: I'm writing a hardware simulator. I have an output buffer
> and need to freeze when it's full and then when called again to resume
> execution from the point where it stopped.

I think the very nature of exceptions prevents this in the
sense you are thinking.  The whole point is that something
unusual has occurred and the current flow of control should
be interrupted and not resumed.

> I'd like to use generators but can't see any "nice" way of doing it.

That would be the approach I would take.  What can't you see
with using yield this way?

> What I'd like it to throw an exception when the buffer is full and then
> next time the generator is called to continue execution as after a
> "yield".

Unlike the exception, the nature of yield is that execution *will*
continue afterwards, so my only advice is to try to find a way to
use generators as you initially thought.

-Peter



More information about the Python-list mailing list