def maybeCallProcessEnded(self):
        """
        Call processEnded on protocol after final cleanup.
        """
        if self.proto is not None:
            reason = self._getReason(self.status)
            proto = self.proto
            self.proto = None
            try:
                proto.processEnded(Failure(reason))
            except:
                err(None, "unexpected error in processEnded")

        Call processEnded on protocol after final cleanup.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/_baseprocess.py