code: def _wait_process_events(self, total_time, return_filter, end_filter):
          
  
          acc = []
          delta = 0.01
  
          start_time = time.time()
          end_time = start_time + total_time
  
          while time.time() < end_time:
              events = self._process_events(lambda x: return_filter(x) or end_filter(x), max_events=1)
              acc += events
  
              for event in events:
                  if end_filter(event):
                      return acc
  
              if len(events) == 0:
                  time.sleep(delta)
  
          return acc
docs: Synchronously process events until a specific event is found or we timeout
  
          Args:
              total_time (float): The aproximate maximum number of seconds we should wait for the end event
              return_filter (callable): A function that returns True for events we should return and not process
                  normally via callbacks to the IOLoop
              end_filter (callable): A function that returns True for the end event that we are looking for to
                  stop processing.
  
          Returns:
              list: A list of events that matched return_filter or end_filter