'The handler which reaps a process is removed when the process is
reaped, even if the protocol\'s C{processEnded} method raises an
exception.'

def test_errorInProcessEnded(self):

    connected = defer.Deferred()
    ended = defer.Deferred()
    scriptPath = 'twisted.test.process_echoer'
    class ErrorInProcessEnded(protocol.ProcessProtocol, ):
        '\n                                                A    protocol    that    raises    an    error    in    C{processEnded}.\n                                                '
        def makeConnection(self, transport):
            connected.callback(transport)
        def processEnded(self, reason):
            reactor.callLater(0, ended.callback, None)
            raise RuntimeError('Deliberate    error')
    reactor.spawnProcess(ErrorInProcessEnded(), pyExe, [pyExe, '-u', '-m', scriptPath], env=properEnv, path=None)
    pid = []
    def cbConnected(transport):
        pid.append(transport.pid)
        self.assertIn(transport.pid, process.reapProcessHandlers)
        transport.loseConnection()
    connected.addCallback(cbConnected)
    def checkTerminated(ignored):
        excs = self.flushLoggedErrors(RuntimeError)
        self.assertEqual(len(excs), 1)
        self.assertNotIn(pid[0], process.reapProcessHandlers)
    ended.addCallback(checkTerminated)
    return ended
