Jonny Flowers
Jonny Flowers

Reputation: 631

How to respond to exceptions in a thread in python

I have some code running in a thread that I need to respond to any exceptions within the calling thread. How would I find out if there are any exceptions and just reboot the child thread?

Upvotes: 2

Views: 204

Answers (2)

urcm
urcm

Reputation: 2284

you can get exception with sth like this:

def run(self):
        while True:                
            try: #yourThread
            except Exception, e: print e

and for restarting a child check out this answer here.

Upvotes: 2

Don Question
Don Question

Reputation: 11614

You would have to terminate/join the child-process in the try/except/finaly-block of the parent thread and afterwards reinvoke it.

Link to an older SO-post, which discusses the "killing" of a thread.

Upvotes: 3

Related Questions