#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2009 Doug Hellmann All rights reserved. # """ """ #end_pymotw_header import sys import threading import time def do_something_with_exception(): exc_type, exc_value = sys.exc_info()[:2] print 'Handling %s exception with message "%s" in %s' % \ (exc_type.__name__, exc_value, threading.current_thread().name) def cause_exception(delay): time.sleep(delay) raise RuntimeError('This is the error message') def thread_target(delay): try: cause_exception(delay) except: do_something_with_exception() threads = [ threading.Thread(target=thread_target, args=(0.3,)), threading.Thread(target=thread_target, args=(0.1,)), ] for t in threads: t.start() for t in threads: t.join()