def _wait_for_any_event(events, timeout_s): """Wait for any in a list of threading.Event's to be set. Args: events: List of threading.Event's. timeout_s: Max duration in seconds to wait before returning. Returns: True if at least one event was set before the timeout expired, else False. """ def any_event_set(): return any(event.is_set() for event in events) result = timeouts.loop_until_timeout_or_true( timeout_s, any_event_set, sleep_s=_WAIT_FOR_ANY_EVENT_POLL_S) return result or any_event_set()
def wait(self, timeout_ms=None): """Block until this command has completed. Args: timeout_ms: Timeout, in milliseconds, to wait. Returns: Output of the command if it complete and self.stdout is a StringIO object or was passed in as None. Returns True if the command completed but stdout was provided (and was not a StringIO object). Returns None if the timeout expired before the command completed. Be careful to check the return value explicitly for None, as the output may be ''. """ closed = timeouts.loop_until_timeout_or_true( timeouts.PolledTimeout.from_millis(timeout_ms), self.stream.is_closed, .1) if closed: if hasattr(self.stdout, 'getvalue'): return self.stdout.getvalue() return True return None