code: def wait_sending_last_messages(self):
          
          if self.active and self.online is not False:
              self.logger.debug("client sends last %s messages ..."
                                % ([str(i) + ':' + str(len(x)) for i, x in six.iteritems(self.queues)],))
  
              for channel, messages in six.iteritems(self.queues):
                  for idx, message in enumerate(messages):
                      self.logger.debug("[%s] %d: %s" % (channel, idx, str(message)[0:120]))
  
              # send all missing messages
  
              # by joining we wait until its loop finish.
              # it won't loop forever since we've set self.stop_on_empty_queue=True
              for channel in six.iterkeys(self.ssh_channel):
                  if channel != '':
                      self._end_channel(channel)
  
              # last is control channel
              self._end_channel('')
docs: Requests all channels to close and waits for it.