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)