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