code: def wait_for_event(self,
                         event_name,
                         predicate,
                         timeout=DEFAULT_TIMEOUT,
                         *args,
                         **kwargs):
          
          deadline = time.time() + timeout
  
          while True:
              event = None
              try:
                  event = self.pop_event(event_name, 1)
              except queue.Empty:
                  pass
  
              if event and predicate(event, *args, **kwargs):
                  return event
  
              if time.time() > deadline:
                  raise queue.Empty(
                      'Timeout after {}s waiting for event: {}'.format(
                          timeout, event_name))
docs: Wait for an event that satisfies a predicate to appear.
  
          Continuously pop events of a particular name and check against the
          predicate until an event that satisfies the predicate is popped or
          timed out. Note this will remove all the events of the same name that
          do not satisfy the predicate in the process.
  
          Args:
              event_name: Name of the event to be popped.
              predicate: A function that takes an event and returns True if the
                  predicate is satisfied, False otherwise.
              timeout: Number of seconds to wait.
              *args: Optional positional args passed to predicate().
              **kwargs: Optional keyword args passed to predicate().
  
          Returns:
              The event that satisfies the predicate.
  
          Raises:
              queue.Empty: Raised if no event that satisfies the predicate was
                  found before time out.