Freeze and Resume execution

Hung Jung Lu hungjunglu at yahoo.com
Thu May 20 16:44:23 EDT 2004


"Miki Tebeka" <miki.tebeka at zoran.com> wrote in message news:<mailman.106.1085054124.6949.python-list at python.org>...
> I'm looking for a way to "yield" an exception.
> ... 
> I'd like to use generators but can't see any "nice" way of doing it.
> 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".

Generators are yielding in the wrong direction, though.

I will assume that you do not have to roll-back changes. (When there
is a roll-back requirement, things get complicated, and
prototype-based languages are more suitable for that purpose.)

while 1:
    try:
        write_output()
        break
    except BufferFullException:
        request_user_intervention()

Would something like that suit your purpose? (The
request_user_intervention() method could be a callback.)

> Is this possible?
> Can you recommend a good way of doing this? Any state machine?

Yes, of course it's possible. IDEs like VB6 and Visual C++ all have
edit-and-continue features. When a bug happens, the program stops. You
have chance to modify some variables, then resume execution from the
point of failure. Similarly, in transaction-enabled software (like
databases), when failures occur, you can even rollback the whole thing
as if nothing has happened.

It all depends on the details of your requirements. The simplest
solution is the one shown above. If that does not meet your
requirements, could you please post further details?

If you do require roll-back, the solution could be very different.
Prototype-based languages are the natural platform for dealing with
this type of problem. But if you do not use PB-OOP, you will have to
create sandbox objects manually, and do the commitment/roll-back by
hand.

State machines are OK, too. (With a workspace object often known as
REQUEST.) But the problem is how granular you want to define your
states. It's a pain when the level of granularity changes. I'd try the
callback approach shown above, before anything else.

The approach shown above can be further refined upon usage of
aspect-oriented-ish mechanics and/or codeblocks. There are many tools
to attack the problem. It all depends on your specific needs.

regards,

Hung Jung



More information about the Python-list mailing list