code: def _close_kernel_socket(self):
          
          if six.PY2 and hasattr(self.socket, '_sock'):
              self.socket._sock.close()
docs: Close kernel socket in outdated Python versions.
  
          On old Python versions,
          Python's socket module does NOT call close on the kernel
          socket when you call socket.close(). We do so manually here
          because we want this server to send a FIN TCP segment
          immediately. Note this must be called *before* calling
          socket.close(), because the latter drops its reference to
          the kernel socket.