code: def wait_until_queue_empty(self, channels, report=True, clear_end=True):
          
          state = {'message': ''}
  
          self.logger.debug("wait_until_queue_empty: report=%s %s"
                            % (str(report), str([channel+':'+str(len(self.queues[channel])) for channel in channels]), ))
          queues = []
          for channel in channels:
              queues += self.queues[channel][:]
  
          def print_progress():
              if report:
                  self.logger.debug("all_empty=%s" % (str(all_empty),))
  
                  sys.__stderr__.write('\b' * len(state['message']))
                  sys.__stderr__.write("\033[K")
  
                  state['message'] = "%.2f kB/s // %.2fkB of %.2fkB // %.2f%%" \
                            % (self.bytes_speed / 1024, self.bytes_sent / 1024, self.bytes_total / 1024,
                              (self.bytes_sent / self.bytes_total * 100) if self.bytes_total else 0)
  
                  sys.__stderr__.write(state['message'])
                  sys.__stderr__.flush()
  
          while True:
              all_empty = all(m['_sent'] for m in queues)
  
              print_progress()
  
              if all_empty:
                  break
  
              time.sleep(0.2)
  
          print_progress()
  
          if report and clear_end:
              sys.__stderr__.write('\b' * len(state['message']))
              sys.__stderr__.write("\033[K")
              sys.__stderr__.flush()
docs: Waits until all queues of channels are empty.