I am using the below class1 code to detect some event through the method check_for_the_event() # Some class1def check_for_the_event(self): thread1 = threading.Timer(2, self.check_for_the_event) thread1.start()# some processingif event is detected: self.event_ok = Trueelse: self.event_ok = False
then I pass an instance of that class to the below class to know when the event is on or off and act upon its value accordingly using the following below code: # execution of other part of the program (where self.another_class_instance.event_ok = False and self.some_other_condition is true) current_time = current_time_some_cond = current_max_time = time.time() while not self.another_class_instance.event_ok and self.some_other_condition: while self.some_other_condition and not self.another_class_instance.event_ok:#self.some_other_condition takes up to 10 secs to be checked (minimum 5 secs) if time.time() > current_time + 5: current_time = time.time() # some processing else: while not self.another_class_instance.event_ok: #processing if time.time() > current_max_time + 60 * 2 and not self.another_class_instance.event_ok: #some other processing if time.time() > current_time_some_cond + 10 and not self.cond1 and not self.another_class_instance.event_ok: # some processing that takes 2-3 seconds self.cond1 = True current_time_some_cond = time.time() elif self.cond1 and time.time() > current_time_some_cond + 10 and not self.another_class_instance.event_ok: current_time_some_cond = time.time() #some other processing that takes 2-3 seconds else: pass else: pass The problem is the real time execution of the program (in class2) requires an instant check to be performed and that cannot wait until the current loop instructions finish, and I want is to break out of the outer while loop if the event is on without further checking any other condition. for now I perform multiple checks at each if or while statement, but is there a IO async based method that breaks out of the loop when the event is raised in the thread? -- https://mail.python.org/mailman/listinfo/python-list