code: def _end_channel(self, channel):
          
          self.stop_on_empty_queue[channel] = True
  
          # by joining the we wait until its loop finishes.
          # it won't loop forever since we've set self.stop_on_empty_queue=True
          write_thread = self.thread_write_instances[channel]
  
          thread_join_non_blocking(write_thread)
docs: Soft end of ssh channel. End the writing thread as soon as the message queue is empty.