Re: Freeze and Resume execution
From: Hung Jung Lu (hungjunglu_at_yahoo.com)
Date: 05/20/04
- Next message: Gian Mario Tagliaretti: "stat module"
- Previous message: Marco Terzuoli: "Redrawing GUI while in a for loop"
- In reply to: Miki Tebeka: "Freeze and Resume execution"
- Next in thread: Shalabh Chaturvedi: "Re: Freeze and Resume execution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 May 2004 13:44:23 -0700
"Miki Tebeka" <miki.tebeka@zoran.com> wrote in message news:<mailman.106.1085054124.6949.python-list@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
- Next message: Gian Mario Tagliaretti: "stat module"
- Previous message: Marco Terzuoli: "Redrawing GUI while in a for loop"
- In reply to: Miki Tebeka: "Freeze and Resume execution"
- Next in thread: Shalabh Chaturvedi: "Re: Freeze and Resume execution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|