當前位置: 首頁>>代碼示例>>Python>>正文


Python error.ProcessExitedAlready方法代碼示例

本文整理匯總了Python中twisted.internet.error.ProcessExitedAlready方法的典型用法代碼示例。如果您正苦於以下問題:Python error.ProcessExitedAlready方法的具體用法?Python error.ProcessExitedAlready怎麽用?Python error.ProcessExitedAlready使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.ProcessExitedAlready方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: signalProcess

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def signalProcess(self, signalID):
        """
        Send the given signal C{signalID} to the process. It'll translate a
        few signals ('HUP', 'STOP', 'INT', 'KILL', 'TERM') from a string
        representation to its int value, otherwise it'll pass directly the
        value provided

        @type signalID: C{str} or C{int}
        """
        if signalID in ('HUP', 'STOP', 'INT', 'KILL', 'TERM'):
            signalID = getattr(signal, 'SIG%s' % (signalID,))
        if self.pid is None:
            raise ProcessExitedAlready()
        try:
            os.kill(self.pid, signalID)
        except OSError as e:
            if e.errno == errno.ESRCH:
                raise ProcessExitedAlready()
            else:
                raise 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:process.py

示例2: test_openingTTY

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def test_openingTTY(self):
        scriptPath = b"twisted.test.process_tty"
        p = Accumulator()
        d = p.endedDeferred = defer.Deferred()
        reactor.spawnProcess(p, pyExe, [pyExe, b"-u", b"-m", scriptPath],
                             env=properEnv, usePTY=self.usePTY)
        p.transport.write(b"hello world!\n")

        def processEnded(ign):
            self.assertRaises(
                error.ProcessExitedAlready, p.transport.signalProcess, 'HUP')
            self.assertEqual(
                p.outF.getvalue(),
                b"hello world!\r\nhello world!\r\n",
                ("Error message from process_tty "
                 "follows:\n\n%s\n\n" % (p.outF.getvalue(),)))
        return d.addCallback(processEnded) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_process.py

示例3: testOpeningTTY

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def testOpeningTTY(self):
        exe = sys.executable
        scriptPath = util.sibpath(__file__, "process_tty.py")
        p = Accumulator()
        d = p.endedDeferred = defer.Deferred()
        reactor.spawnProcess(p, exe, [exe, "-u", scriptPath], env=None,
                            path=None, usePTY=self.usePTY)
        p.transport.write("hello world!\n")

        def processEnded(ign):
            self.assertRaises(
                error.ProcessExitedAlready, p.transport.signalProcess, 'HUP')
            self.assertEquals(
                p.outF.getvalue(),
                "hello world!\r\nhello world!\r\n",
                "Error message from process_tty follows:\n\n%s\n\n" % p.outF.getvalue())
        return d.addCallback(processEnded) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_process.py

示例4: stopProcess

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:20,代碼來源:procmon.py

示例5: kill

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def kill(self):
        try:
            self.transport.signalProcess('KILL')
        except internet_error.ProcessExitedAlready:
            self.log.debug('Process Exited Already') 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:7,代碼來源:process.py

示例6: signalProcess

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def signalProcess(self, signalID):
        if self.pid is None:
            raise error.ProcessExitedAlready()
        if signalID in ("INT", "TERM", "KILL"):
            win32process.TerminateProcess(self.hProcess, 1) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:_dumbwin32proc.py

示例7: closed

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:unix.py

示例8: tearDown

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:test_recvline.py

示例9: _reallyDie

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def _reallyDie(self):
        try:
            self.transport.signalProcess('KILL')
        except ProcessExitedAlready:
            pass 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_conch.py

示例10: test_process

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:30,代碼來源:test_process.py

示例11: test_killExited

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:test_process.py

示例12: test_killExitedButNotDetected

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:17,代碼來源:test_process.py

示例13: _forceStopProcess

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def _forceStopProcess(self, proc):
        """
        @param proc: An L{IProcessTransport} provider
        """
        try:
            proc.signalProcess('KILL')
        except error.ProcessExitedAlready:
            pass 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:10,代碼來源:procmon.py

示例14: connectionMade

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
def connectionMade(self):
        @defer.inlineCallbacks
        def killIfAlive():
            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) 
開發者ID:calston,項目名稱:tensor,代碼行數:12,代碼來源:utils.py

示例15: _terminate

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessExitedAlready [as 別名]
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 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:15,代碼來源:watchdog.py


注:本文中的twisted.internet.error.ProcessExitedAlready方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。