How can I better write the following class? For example is there a nice way to slip having the two flags is_alive and is_finished?
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)