Код: Выделить всё
check_for_the_event()
# Some class1
def check_for_the_event(self):
thread1 = threading.Timer(2, self.check_for_the_event)
thread1.start()
# some processing
if event is detected:
self.event_ok = True
else:
self.event_ok = False
Код: Выделить всё
# 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
на данный момент я выполняю несколько проверок для каждого оператора if или while, но есть ли асинхронный ввод-вывод метод, который выходит из цикла, когда событие возникает в нить?
Подробнее здесь: https://stackoverflow.com/questions/792 ... -on-events
Мобильная версия