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 ) |
| 20 | ''' |
| 21 | if self.target is not None: |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 22 | if len(self.args) != 0: |
| 23 | self.result = self.target( *self.args ) |
| 24 | else: |
| 25 | self.result = self.target() |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 26 | # FIXME: handle kwargs? |
| 27 | ''' |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 28 | except Exception as e: |
Jon Hall | 65844a3 | 2015-03-09 19:09:37 -0700 | [diff] [blame] | 29 | print "Thread-" + str( self.threadID ) + " '" + self.name + "'"\ |
| 30 | ":something went wrong with " + self.target + " method" |
kelvin-onlab | 54400a9 | 2015-02-26 18:05:51 -0800 | [diff] [blame] | 31 | print e |