code: def _thread_error(self, thread):
          
  
          # Avoid double-killing the thread
          if thread == self._send_thread:
              self._send_thread = None
          if thread == self._recv_thread:
              self._recv_thread = None
  
          # Figure out why the thread exited
          if thread.successful():
              exception = socket.error('thread exited prematurely')
          elif isinstance(thread.exception, gevent.GreenletExit):
              # Thread was killed; don't do anything but close
              self.close()
              return
          else:
              exception = thread.exception
  
          # Close the connection...
          self.close()
  
          # Notify the application what happened
          self.closed(exception)
docs: Handles the case that the send or receive thread exit or throw
          an exception.