Reputation: 9
Please Help on my code with threads. it goes like
class MyThread(threading.Thread): # Create a class representing a thread of control
def __init__(self,target):
print 'thread created'
self.target = target
threading.Thread.__init__ ( self )
def run (self):
print 'running thread '
while True:
self.target()
# Define class to allow thread to be stopped over time
def __init__ (self, target):
super(MyThread, self).__init__()
self._stop = threading.Event()
print "thread stopped"
def stop (self):
self._stop.set()
def stopped (self):
return self._stop.isSet()
However when i run it, it complains that the line self.target () : 'MyThread' object has no attribute 'target'
how do i get around this?
Upvotes: 0
Views: 2081
Reputation: 76949
Uhm... you are overriding your own init method, and the override doesn't assign the self.target variable.
Upvotes: 0
Reputation: 13121
You have two init functions defined. The second definition (which doesn't define target) overrides the first.
Upvotes: 4