MyThread 클래스가 있습니다. 그 안에 메서드 샘플이 있습니다. 동일한 개체 컨텍스트 내에서 실행하려고합니다. 코드를보세요 :
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()
매우 간단 해 보이지 않습니다. 하지만 실행하면이 오류가 발생합니다.
AttributeError: 'myThread' object has no attribute 'sample'이제 그 방법이 있습니다. 그래서 무엇이 잘못 되었나요? 도와주세요
편집 : 이것은 스택 트레이스입니다
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'
이렇게 부르고있어
arThreads = []
maxThreads = 2;
for i in range( maxThreads ):
redisOpsObj = redisOps()
arThreads.append( myThread(i, "Thread-"+str(i), 10, redisOpsObj) )
redisOps 수업 코드를 게시 할 수 없습니다. 하지만 잘 작동한다고 확신 할 수 있습니다.