-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThreadUtil.py
More file actions
40 lines (33 loc) · 1.02 KB
/
ThreadUtil.py
File metadata and controls
40 lines (33 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Author: AsherYang
Email : ouyangfan1991@gmail.com
Date : 2018/9/13
Desc : 线程工具类, 将线程的异常信息上报传递给主线程。
主线程可检测线程异常
https://blog.csdn.net/linchere/article/details/49587479
"""
import threading, traceback, sys, os
class ThreadUtil(threading.Thread):
def __init__(self, funcName, **args):
threading.Thread.__init__(self)
self.exitCode = 0
self.exception = None
self.exc_traceback = ''
self.funcName = funcName
self.args = args
def run(self):
try:
self._run()
except Exception as e:
self.exitCode = 1
self.exception = e
self.exc_traceback = ''.join(traceback.format_exception(*sys.exc_info()))
# print 'self.exc_traceback: ', self.exc_traceback
raise e
def _run(self):
try:
self.funcName(**(self.args))
except Exception as e:
raise e