如何在python中响应线程中的异常

如何在python中响应线程中的异常,python,multithreading,exception-handling,Python,Multithreading,Exception Handling,我有一些代码运行在一个线程中,我需要响应调用线程中的任何异常。如何查明是否存在异常并重新启动子线程?您必须在父线程的try/except/finally-块中终止/加入子进程,然后重新调用它 到一篇较老的SO帖子,该帖子讨论了线程的“终止”。你可以得到如下异常: def run(self): while True: try: #yourThread except Exception, e: print

我有一些代码运行在一个线程中,我需要响应调用线程中的任何异常。如何查明是否存在异常并重新启动子线程?

您必须在父线程的
try/except/finally
-块中终止/加入子进程,然后重新调用它


到一篇较老的SO帖子,该帖子讨论了线程的“终止”。

你可以得到如下异常:

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

要重新启动孩子,请查看此答案。

我能看到关于如何实现此功能的示例代码吗?