import threading, time
class test(threading.Thread):
def __init__(self,name,delay):
threading.Thread.__init__(self)
self.name = name
self.delay = delay
def run(self):
c = 0
while True:
time.sleep(self.delay)
print 'This is thread %s on line %s' %(self.name,c)
c = c + 1
if c == 15:
print 'End of thread %s' % self.name
break
one = test('one', 1).start()
two = test('two', 3).start()
one.join()
two.join()
print 'End of main'
문제 : 내가 제거하면파이썬 - 멀티 스레딩 - 가입() 메소드
Traceback (most recent call last)line 29, in <module> join() NameError: name 'join' is not defined
: 제대로 작동하려면() 메소드에 가입 얻을 수없는, 다음과 같은 오류를 제공
one.join
two.join
코드가 완벽하게 작동합니다.
나는 두 개의 스레드가 끝난 후,print 'End of main'
을 마지막 줄을 인쇄하고 싶었다. join()이 두 인스턴스의 속성이 아닌 이유를 이해할 수없는 것 같습니다.
당신의 intendation는 나사된다. –
죄송합니다 - 초보자는 여기에 있습니다. 나 시도했다 – mrdigital
나는 당신의 포스트에서 다만 의미한다. 나는 당신의 프로그램이 다르게 보인다고 생각한다. –