Beispiel #1
0
    def test_processExitedRaises(self):
        """
        If L{IProcessProtocol.processExited} raises an exception, it is logged.
        """
        # Ideally we wouldn't need to poke the process module; see
        # https://twistedmatrix.com/trac/ticket/6889
        reactor = self.buildReactor()

        class TestException(Exception):
            pass

        class Protocol(ProcessProtocol):
            def processExited(self, reason):
                reactor.stop()
                raise TestException("processedExited raised")

        protocol = Protocol()
        transport = reactor.spawnProcess(protocol,
                                         pyExe, [pyExe, b"-c", b""],
                                         usePTY=self.usePTY)
        self.runReactor(reactor)

        # Manually clean-up broken process handler.
        # Only required if the test fails on systems that support
        # the process module.
        if process is not None:
            for pid, handler in items(process.reapProcessHandlers):
                if handler is not transport:
                    continue
                process.unregisterReapProcessHandler(pid, handler)
                self.fail("After processExited raised, transport was left in"
                          " reapProcessHandlers")

        self.assertEqual(1, len(self.flushLoggedErrors(TestException)))
    def test_processExitedRaises(self):
        """
        If L{IProcessProtocol.processExited} raises an exception, it is logged.
        """
        # Ideally we wouldn't need to poke the process module; see
        # https://twistedmatrix.com/trac/ticket/6889
        reactor = self.buildReactor()

        class TestException(Exception):
            pass

        class Protocol(ProcessProtocol):
            def processExited(self, reason):
                reactor.stop()
                raise TestException("processedExited raised")

        protocol = Protocol()
        transport = reactor.spawnProcess(
               protocol, pyExe, [pyExe, b"-c", b""],
               usePTY=self.usePTY)
        self.runReactor(reactor)

        # Manually clean-up broken process handler.
        # Only required if the test fails on systems that support
        # the process module.
        if process is not None:
            for pid, handler in items(process.reapProcessHandlers):
                if handler is not transport:
                    continue
                process.unregisterReapProcessHandler(pid, handler)
                self.fail("After processExited raised, transport was left in"
                          " reapProcessHandlers")

        self.assertEqual(1, len(self.flushLoggedErrors(TestException)))
Beispiel #3
0
def reapProcess(self):
    """Try to reap a process (without blocking) via waitpid.
    
    This is called when sigchild is caught or a Process object loses its
    "connection" (stdout is closed) This ought to result in reaping all
    zombie processes, since it will be called twice as often as it needs
    to be.

    (Unfortunately, this is a slightly experimental approach, since
    UNIX has no way to be really sure that your process is going to
    go away w/o blocking.  I don't want to block.)

    We replace Twisted's version with another that tolerates a
    non-integer self.pid.
    """
    try:
        pid, status = os.waitpid(self.pid, os.WNOHANG)
    except:
        tLog.msg('Failed to reap %s:' % str(self.pid)) # This line changed.
        tLog.err()
        pid = None
    if pid:
        self.processEnded(status)
        unregisterReapProcessHandler(pid, self)