def _expect(self, expected, timeout=DEFAULT_TIMEOUT_S): """ We may (and often do) get an indication/notification before a write completes, and so it can be lost if we "expect()"'d something that came after it in the output, e.g.: > char-write-req 0x1 0x2 Notification handle: xxx Write completed successfully. > Anytime we expect something we have to expect noti/indication first for a short time. """ with self._connection_lock: patterns = [ expected, 'Notification handle = .*? \r', 'Indication handle = .*? \r', '.*Invalid file descriptor.*', '.*Disconnected\r', ] while True: try: matched_pattern_index = self._con.expect(patterns, timeout) if matched_pattern_index == 0: break elif matched_pattern_index in [1, 2]: self._handle_notification_string(self._con.after) elif matched_pattern_index == 3: if self._running.is_set(): log.info("Disconnected") except pexpect.TIMEOUT: raise NotificationTimeout( "Timed out waiting for a notification")
def wait(self, event, timeout=None): """ Wait for event to be trigerred """ if not self._event_vector[event]["event"].wait(timeout*3): print("wait event:{} but timeout:{}".format(event, timeout)) raise NotificationTimeout()
def wait(self, event, timeout=None): """ Wait for event to be trigerred """ if not self._event_vector[event]["event"].wait(timeout): raise NotificationTimeout()