7
어떻게하면 다음 클래스를 더 잘 쓸 수 있습니까? 예를 들어 두 플래그 is_alive와 is_finished를 가지고 미끄러지는 좋은 방법이 있습니까?python3에서 스레드 중지
Monitor(threading.Thread):
def run(self):
resource = Resource("com1")
self.alive = True
self.is_finished = False
try:
while self.alive:
pass # use resource
finally:
resource.close()
self.is_finished = True
def stop(self):
self.alive = False
while not self.is_finished:
time.sleep(0.1)