blob: 452437a7761a39daa2bf0d080b93fc699b7f339e [file] [log] [blame]
kelvin-onlab54400a92015-02-26 18:05:51 -08001#!/usr/bin/env python
2import threading
3
Jon Hall65844a32015-03-09 19:09:37 -07004
5class Thread( threading.Thread ):
6 def __init__( self, target=None, threadID=None, name="", args=(),
7 kwargs={} ):
8 super( Thread, self ).__init__()
kelvin-onlab54400a92015-02-26 18:05:51 -08009 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 Hall65844a32015-03-09 19:09:37 -070019 self.result = self.target( *self.args, **self.kwargs )
20 '''
21 if self.target is not None:
kelvin-onlab54400a92015-02-26 18:05:51 -080022 if len(self.args) != 0:
23 self.result = self.target( *self.args )
24 else:
25 self.result = self.target()
Jon Hall65844a32015-03-09 19:09:37 -070026 # FIXME: handle kwargs?
27 '''
kelvin-onlab54400a92015-02-26 18:05:51 -080028 except Exception as e:
Jon Hall65844a32015-03-09 19:09:37 -070029 print "Thread-" + str( self.threadID ) + " '" + self.name + "'"\
30 ":something went wrong with " + self.target + " method"
kelvin-onlab54400a92015-02-26 18:05:51 -080031 print e