[Python-ideas] Thread exceptions and interruption

Adam Olsen rhamph at gmail.com
Wed Sep 19 19:37:29 CEST 2007

On 9/19/07, Guido van Rossum <guido at python.org> wrote:
> On 9/19/07, Adam Olsen <rhamph at gmail.com> wrote:
> > Let's try a simpler example, without the main thread (which isn't
> > special for exception purposes):
> > (Make sure to look at it with a monospace font)
> >
> >            / baz
> > foo - bar +- baz
> >            \ baz
> >
> > bar encapsulates several threads.  It makes no sense unravel the call
> > tree while a lower portion of it still exists, so it must wait.  If
> > there is a failure, bar will politely tell all 3 baz functions to
> > exit, but they probably won't listen (unless they're calling I/O).  If
> > necessary bar will wait forever.
> >
> > foo never sees any of this.  It is completely hidden within bar.
> So what happens if the first baz thread raises an exception that bar
> isn't handling? I suppose it first waits until all baz threads are
> done, but then the question is still open. Does it percolate up to
> foo? What if two or more baz threads raise exceptions? How does foo
> see these?

bar itself doesn't see it until *after* they've all exited.  The
branch construct holds it until all child threads have exited.  There
is no way to get weird stack unwinding.

If multiple exceptions occur they get encapsulated in a MultipleError exception.

Adam Olsen, aka Rhamphoryncus

More information about the Python-ideas mailing list