def loseConnection(self):
        """
        Close this connection after writing all pending data.

        If TLS has been negotiated, perform a TLS shutdown.
        """
        if self.TLS:
            if self.connected and not self.disconnecting:
                self.protocol.loseConnection()
        else:
            FileDescriptor.loseConnection(self)

        Close this connection after writing all pending data.

        If TLS has been negotiated, perform a TLS shutdown.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/_newtls.py