Howto pass exceptions between threads

Discussion in 'Python' started by Alexander Eisenhuth, Mar 5, 2007.

  1. Hallo Alltogether,

    I've searched in this mailing list, but it seems to me that there is no general
    approach to pass exceptions from one thread to another.

    I think most application do a unique way of handling "unhandled exceptions", at
    least they (should) try to log them.

    The following discussion seems to me most valuable (Sorry for the long URL, I
    don't know a way of shorter)

    http://groups.google.de/group/comp....ception +thread&rnum=6&hl=de#4b820c20ff3fcea8
    http://groups.google.de/group/comp....ception +thread&rnum=1&hl=de#348a8d9e85883fe3

    I've the feeling that if you're using the python class threading.Thread you've a
    unique interface of handling it. (thread synchronizing + exception raising)

    But' when you've a C++ extension, that uses it's own thread implementation and
    your exceptions happens in python code (but from a thread that is controlled by
    your extension) you have another problem.

    Maybe I've overseen something in the python docu, so I ask for the solutions,
    concepts, hints ... you solved the problem.

    Regards
    Alexander
     
    Alexander Eisenhuth, Mar 5, 2007
    #1
    1. Advertising

  2. Alexander Eisenhuth

    John Nagle Guest

    Alexander Eisenhuth wrote:
    > Hallo Alltogether,
    >
    > I've searched in this mailing list, but it seems to me that there is no
    > general approach to pass exceptions from one thread to another.


    Very few languages have that.

    Actually, it could be made to work for Python, but it would have to
    be carefully designed. Something that raises an exception in another
    thread the next time the thread blocks would have relatively sane
    semantics. You couldn't raise an exception on a compute-bound thread,
    only at block points (locks, I/O, long system calls.)

    John Nagle
     
    John Nagle, Mar 5, 2007
    #2
    1. Advertising

  3. John Nagle schrieb:
    > Alexander Eisenhuth wrote:
    >> Hallo Alltogether,
    >>
    >> I've searched in this mailing list, but it seems to me that there is
    >> no general approach to pass exceptions from one thread to another.

    >
    > Very few languages have that.
    >
    > Actually, it could be made to work for Python, but it would have to
    > be carefully designed. Something that raises an exception in another
    > thread the next time the thread blocks would have relatively sane
    > semantics. You couldn't raise an exception on a compute-bound thread,
    > only at block points (locks, I/O, long system calls.)
    >
    > John Nagle


    Yes you're right, it must be well designed with a clear responsibility
    delegation. I can imgagine the following points:

    - Thread termination with termination handler (for Thread instance)
    - Main Thread information / synchronisation
    - Default/Customized main thread exception handler
     
    Alexander Eisenhuth, Mar 6, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ahmed Moustafa
    Replies:
    5
    Views:
    30,067
    Chris Smith
    Jul 14, 2004
  2. shaun82
    Replies:
    3
    Views:
    1,135
    Esmond Pitt
    Apr 5, 2005
  3. Sako
    Replies:
    3
    Views:
    5,627
  4. blufox
    Replies:
    2
    Views:
    575
  5. Sako
    Replies:
    2
    Views:
    170
Loading...

Share This Page