kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import threading |
| 3 | |
| 4 | class Thread(threading.Thread): |
| 5 | def __init__(self, target = None, threadID=None, name="", args=(), kwargs={}): |
| 6 | super(Thread, self).__init__() |
| 7 | self.threadID = threadID |
| 8 | self.name = name |
| 9 | self.target = target |
| 10 | self.args = args |
| 11 | self.kwargs = kwargs |
| 12 | self.result = None |
| 13 | |
| 14 | def run( self ): |
| 15 | try: |
| 16 | if self.target is not None: |
| 17 | if len(self.args) != 0: |
| 18 | self.result = self.target( *self.args ) |
| 19 | else: |
| 20 | self.result = self.target() |
| 21 | except Exception as e: |
| 22 | print "Thread-" + str(self.threadID) + \ |
| 23 | ":something went wrong with " + self.name + " method" |
| 24 | print e |