[Stackless] RE: [Python-Dev] uthread strawman

Tim Peters tim_one at email.msn.com
Sat Nov 11 10:47:10 CET 2000


[Moshe]
> I imagined something like
>
> try:
> 	raise RestartableException, continuation.current_continuation()
> except RestartableException, ex:
> 	# correct the problem
> 	ex.saved_continuation()
>
> IOW, just put the continuation in the exception object.
> I don't think you can use generators/coroutines to simulate something
> like this

[Guido]
> You can make the exception handler into a separate coroutine -- then
> no reusable continuations are needed.  The coroutine can repair the
> exception and resume the other.

Since I'm not a fan of resumable exceptions, I won't beat it to death.

Note that there are at least three meanings for "resumable exception" in
actual use (and I believe, e.g., that modern (ANSI) Smalltalk supports all
three):

1. Handler returns a value, and the failing operation acts as if that were
what it had computed from the start.  Very common in HW (e.g., a page fault
on a memory load acts this way; ditto 1e300**2 returning +Inf under 754
double arithmetic when the overflow signal is masked out).  Note that no
lexically enclosing "try block" is needed in this case (it is in the next
two, although they don't need "except" clauses attached to their lexically
enclosing "try").

2. Handler tells the entire originating "try block" to start over.

3. Handler resumes right after the originating try block.

In all of these, you have to search "up the call stack" for a handler, which
then wants to resume as if the call stack had not been unwound (albeit that
in #2 and #3, wants to resume at different places than where the exception
was raised!).  "Up the call stack" means within your current thread of
control, so it's hard to see how to make an independent coroutine out of
that on demand (the handler needs to work in its natural lexical context,
incl. modifying values of *its* scope's locals that will be visible again
when the deeper routine with the exception eventually does normal returns
back to it).

The details are excruciating -- so it's a good thing nobody in their right
mind wants any of these <wink>.

relievedly y'rs  - tim


_______________________________________________
Stackless mailing list
Stackless at starship.python.net
http://starship.python.net/mailman/listinfo/stackless



More information about the Stackless mailing list