Tengo una clase MyThread. En eso tengo una muestra de método. Estoy intentando ejecutarlo desde el mismo contexto de objeto. Por favor, eche un vistazo al código:Python AttributeError: El objeto no tiene ningún atributo
class myThread (threading.Thread):
def __init__(self, threadID, name, counter, redisOpsObj):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
self.redisOpsObj = redisOpsObj
def stop(self):
self.kill_received = True
def sample(self):
print "Hello"
def run(self):
time.sleep(0.1)
print "\n Starting " + self.name
self.sample()
Parece muy simple ¿no? Pero cuando lo ejecuto obtengo este error
AttributeError: 'myThread' object has no attribute 'sample'
Ahora tengo ese método, allí mismo. ¿Así que qué hay de malo? Por favor, ayuda
Editar: Esta es la StackTrace
Starting Thread-0
Starting Thread-1
Exception in thread Thread-0:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "./redisQueueProcessor.py", line 51, in run
self.sample()
AttributeError: 'myThread' object has no attribute 'sample'
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "./redisQueueProcessor.py", line 51, in run
self.sample()
AttributeError: 'myThread' object has no attribute 'sample'
estoy llamando como este código de clase
arThreads = []
maxThreads = 2;
for i in range(maxThreads):
redisOpsObj = redisOps()
arThreads.append(myThread(i, "Thread-"+str(i), 10, redisOpsObj))
Lo siento, no puedo publicar redisOps. Pero puedo asegurarle que funciona bien
¿Publicaría el error completo con la pila de llamadas? – sloth
¿podría agregar el código de cómo está llamando? – Babu
¿Falta algún código? Este fragmento funciona fien para mí. – ThirdOne