Python twisted.internet.error 模块,ProcessExitedAlready() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用twisted.internet.error.ProcessExitedAlready()

项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def stopProcess(self, name):
        """
        @param name: The name of the process to be stopped
        """
        if name not in self.processes:
            raise KeyError('Unrecognized process name: %s' % (name,))

        proto = self.protocols.get(name, None)
        if proto is not None:
            proc = proto.transport
            try:
                proc.signalProcess('TERM')
            except error.ProcessExitedAlready:
                pass
            else:
                self.murder[name] = self._reactor.callLater(
                                            self.killTime,
                                            self._forceStopProcess, proc)
项目:docker-zenoss4    作者:krull    | 项目源码 | 文件源码
def stop(self):
        """
        Twisted reactor function called when we are shutting down.
        """
        import signal
        self.log.info('stop():stopping zenjmxjava')
        self.stopCalled = True
        if not self.process:
            self.log.debug('stop():no zenjmxjava process to stop')
            return
        try:
            self.process.signalProcess(signal.SIGKILL)
        except error.ProcessExitedAlready:
            self.log.info('stop():zenjmxjava process already exited')
            pass
        try:
            self.process.loseConnection()
        except Exception:
            pass
        self.process = None
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def reallyDie(self):
        try:
            self.proto.transport.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def _killProcess(self, ignored):
        try:
            self.processProtocol.transport.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass
项目:bitmask-dev    作者:leapcode    | 项目源码 | 文件源码
def kill(self):
        try:
            self.transport.signalProcess('KILL')
        except internet_error.ProcessExitedAlready:
            self.log.debug('Process Exited Already')
项目:landscape-client    作者:CanonicalLtd    | 项目源码 | 文件源码
def _terminate(self, warn=False):
        if self.transport is not None:
            if warn:
                warning("%s didn't exit. Sending SIGTERM"
                        % (self.daemon.program,))
            try:
                self.transport.signalProcess(signal.SIGTERM)
            except ProcessExitedAlready:
                pass
            else:
                # Give some time for the process, and then show who's the boss.
                delayed = reactor.callLater(SIGKILL_DELAY, self._really_kill)
                self._delayed_really_kill = delayed
项目:landscape-client    作者:CanonicalLtd    | 项目源码 | 文件源码
def _really_kill(self):
        try:
            self.transport.signalProcess(signal.SIGKILL)
        except ProcessExitedAlready:
            pass
        else:
            warning("%s didn't die.  Sending SIGKILL." % self.daemon.program)
        self._delayed_really_kill = None
项目:landscape-client    作者:CanonicalLtd    | 项目源码 | 文件源码
def rotate_logs(self):
        if self.transport is not None:
            try:
                self.transport.signalProcess(signal.SIGUSR1)
            except ProcessExitedAlready:
                pass
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def reallyDie(self):
        try:
            self.proto.transport.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def _killProcess(self, ignored):
        try:
            self.processProtocol.transport.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def tearDown(self):
        # Kill the child process.  We're done with it.
        try:
            self.clientTransport.signalProcess("KILL")
        except (error.ProcessExitedAlready, OSError):
            pass
        def trap(failure):
            failure.trap(error.ProcessTerminated)
            self.assertIsNone(failure.value.exitCode)
            self.assertEqual(failure.value.status, 9)
        return self.testTerminal.onDisconnection.addErrback(trap)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def _reallyDie(self):
        try:
            self.transport.signalProcess('KILL')
        except ProcessExitedAlready:
            pass
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def _killProcess(self, ignored):
        try:
            self.processProtocol.transport.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def closed(self):
        if self.ptyTuple and os.path.exists(self.ptyTuple[2]):
            ttyGID = os.stat(self.ptyTuple[2])[5]
            os.chown(self.ptyTuple[2], 0, ttyGID)
        if self.pty:
            try:
                self.pty.signalProcess('HUP')
            except (OSError, ProcessExitedAlready):
                pass
            self.pty.loseConnection()
            self.addUTMPEntry(0)
        log.msg('shell closed')
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def signalProcess(self, signalID):
        if self.pid is None:
            raise error.ProcessExitedAlready()
        if signalID in ("INT", "TERM", "KILL"):
            win32process.TerminateProcess(self.hProcess, 1)
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def _forceStopProcess(self, proc):
        """
        @param proc: An L{IProcessTransport} provider
        """
        try:
            proc.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_process(self):
        """
        Test running a process: check its output, it exitCode, some property of
        signalProcess.
        """
        scriptPath = b"twisted.test.process_tester"
        d = defer.Deferred()
        p = TestProcessProtocol()
        p.deferred = d
        reactor.spawnProcess(p, pyExe, [pyExe, b"-u", b"-m", scriptPath],
                             env=properEnv)
        def check(ignored):
            self.assertEqual(p.stages, [1, 2, 3, 4, 5])
            f = p.reason
            f.trap(error.ProcessTerminated)
            self.assertEqual(f.value.exitCode, 23)
            # would .signal be available on non-posix?
            # self.assertIsNone(f.value.signal)
            self.assertRaises(
                error.ProcessExitedAlready, p.transport.signalProcess, 'INT')
            try:
                import process_tester, glob
                for f in glob.glob(process_tester.test_file_match):
                    os.remove(f)
            except:
                pass
        d.addCallback(check)
        return d
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_killExited(self):
        """
        L{process.Process.signalProcess} raises L{error.ProcessExitedAlready}
        if the process has exited.
        """
        self.mockos.child = False
        cmd = b'/mock/ouch'
        p = TrivialProcessProtocol(None)
        proc = reactor.spawnProcess(p, cmd, [b'ouch'], env=None, usePTY=False)
        # We didn't specify a waitpid value, so the waitpid call in
        # registerReapProcessHandler has already reaped the process
        self.assertRaises(error.ProcessExitedAlready,
                          proc.signalProcess, "KILL")
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_killExitedButNotDetected(self):
        """
        L{process.Process.signalProcess} raises L{error.ProcessExitedAlready}
        if the process has exited but that twisted hasn't seen it (for example,
        if the process has been waited outside of twisted): C{os.kill} then
        raise C{OSError} with C{errno.ESRCH} as errno.
        """
        self.mockos.child = False
        self.mockos.waitChild = (0, 0)
        cmd = b'/mock/ouch'
        p = TrivialProcessProtocol(None)
        proc = reactor.spawnProcess(p, cmd, [b'ouch'], env=None, usePTY=False)
        self.mockos.raiseKill = OSError(errno.ESRCH, "Not found")
        self.assertRaises(error.ProcessExitedAlready,
                          proc.signalProcess, "KILL")
项目:duct    作者:ducted    | 项目源码 | 文件源码
def connectionMade(self):
        @defer.inlineCallbacks
        def killIfAlive():
            """Terminate after timeout if still alive
            """
            try:
                yield self.transport.signalProcess('KILL')
                log.msg('Killed source proccess: Timeout %s exceeded'
                        % self.timeout)
            except error.ProcessExitedAlready:
                pass

        self.timer = reactor.callLater(self.timeout, killIfAlive)
项目:ooniprobe-debian    作者:TheTorProject    | 项目源码 | 文件源码
def test_full_tor_connection(self):
        config = txtorcon.TorConfig()
        config.ControlPort = net.randomFreePort()
        config.SocksPort = net.randomFreePort()
        config.DataDirectory = self.tor_datadir
        log.msg(
            "Connecting to tor %s" %
            (onion.tor_details['version']))

        config.log = ['notice stdout', 'notice file %s' % self.tor_logfile]
        config.save()

        def updates(prog, tag, summary):
            log.msg("Progress is at: %s%%" % (prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
                                progress_updates=updates)

        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to Tor")
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to Tor")
            self.report['success'] = False
            self.report['error'] = 'timeout-reached'
            return

        @d.addCallback
        def write_log(_):
            with open(self.tor_logfile) as f:
                self.report['tor_log'] = f.read()
            os.remove(self.tor_logfile)
            try:
                shutil.rmtree(self.tor_datadir)
            except:
                pass

        return d