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


Python error.ProcessDone方法代碼示例

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


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

示例1: processExited

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def processExited(self, failure):
        err = failure.trap(
            internet_error.ProcessDone, internet_error.ProcessTerminated)

        if err == internet_error.ProcessDone:
            pass

        elif err == internet_error.ProcessTerminated:
            self.failed = True
            self.errmsg = failure.value.exitCode
            if self.errmsg:
                self.log.debug('Process Exited, status %d' % (self.errmsg,))
            else:
                self.log.warn('%r' % failure.value)
        if IS_MAC:
            # TODO: need to exit properly!
            self.errmsg = None
        self.proto = None
        self._turn_state_off() 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:21,代碼來源:process.py

示例2: test_stdin

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_stdin(self):
        """
        Making sure getPassword accepts a password from standard input by
        running a child process which uses getPassword to read in a string
        which it then writes it out again.  Write a string to the child
        process and then read one and make sure it is the right string.
        """
        p = PasswordTestingProcessProtocol()
        p.finished = Deferred()
        reactor.spawnProcess(
            p, pyExe,
            [pyExe,
             b'-c',
             (b'import sys\n'
              b'from twisted.python.util import getPassword\n'
              b'sys.stdout.write(getPassword())\n'
              b'sys.stdout.flush()\n')],
            env={b'PYTHONPATH': os.pathsep.join(sys.path).encode("utf8")})

        def processFinished(result):
            (reason, output) = result
            reason.trap(ProcessDone)
            self.assertIn((1, b'secret'), output)

        return p.finished.addCallback(processFinished) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:27,代碼來源:test_util.py

示例3: test_loseConnection

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_loseConnection(self):
        """
        Verify that a protocol connected to L{StandardIO} can disconnect
        itself using C{transport.loseConnection}.
        """
        errorLogFile = self.mktemp()
        log.msg("Child process logging to " + errorLogFile)
        p = StandardIOTestProcessProtocol()
        d = p.onCompletion
        self._spawnProcess(p, b'stdio_test_loseconn', errorLogFile)

        def processEnded(reason):
            # Copy the child's log to ours so it's more visible.
            with open(errorLogFile, 'r') as f:
                for line in f:
                    log.msg("Child logged: " + line.rstrip())

            self.failIfIn(1, p.data)
            reason.trap(error.ProcessDone)
        return self._requireFailure(d, processEnded) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_stdio.py

示例4: test_readConnectionLost

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_readConnectionLost(self):
        """
        When stdin is closed and the protocol connected to it implements
        L{IHalfCloseableProtocol}, the protocol's C{readConnectionLost} method
        is called.
        """
        errorLogFile = self.mktemp()
        log.msg("Child process logging to " + errorLogFile)
        p = StandardIOTestProcessProtocol()
        p.onDataReceived = defer.Deferred()

        def cbBytes(ignored):
            d = p.onCompletion
            p.transport.closeStdin()
            return d
        p.onDataReceived.addCallback(cbBytes)

        def processEnded(reason):
            reason.trap(error.ProcessDone)
        d = self._requireFailure(p.onDataReceived, processEnded)

        self._spawnProcess(
            p, b'stdio_test_halfclose', errorLogFile)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:26,代碼來源:test_stdio.py

示例5: test_consumer

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_consumer(self):
        """
        Verify that the transport of a protocol connected to L{StandardIO}
        is a working L{IConsumer} provider.
        """
        p = StandardIOTestProcessProtocol()
        d = p.onCompletion

        junkPath = self._junkPath()

        self._spawnProcess(p, b'stdio_test_consumer', junkPath)

        def processEnded(reason):
            with open(junkPath, 'rb') as f:
                self.assertEqual(p.data[1], f.read())
            reason.trap(error.ProcessDone)
        return self._requireFailure(d, processEnded) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_stdio.py

示例6: test_list_result_ignores_other_pools

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_list_result_ignores_other_pools(self):
        """
        ``ZFSSnapshots.list`` skips snapshots of other pools.

        In particular, we are likely to see snapshot names of sub-pools in
        the output.
        """
        reactor = FakeProcessReactor()
        snapshots = ZFSSnapshots(reactor, Filesystem(b"mypool", None))

        d = snapshots.list()
        process_protocol = reactor.processes[0].processProtocol
        process_protocol.childDataReceived(1, b"mypool/child@name\n")
        process_protocol.childDataReceived(1, b"mypool@name2\n")
        reactor.processes[0].processProtocol.processEnded(
            Failure(ProcessDone(0)))
        self.assertEqual(self.successResultOf(d), [b"name2"]) 
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:19,代碼來源:test_filesystems_zfs.py

示例7: test_outputWithErrorIgnored

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_outputWithErrorIgnored(self):
        """
        The L{Deferred} returned by L{getProcessOutput} is fired with an
        L{IOError} L{Failure} if the child process writes to stderr.
        """
        # make sure stderr raises an error normally
        scriptFile = self.makeSourceFile([
            'import sys',
            'sys.stderr.write("hello world\\n")'
            ])

        d = utils.getProcessOutput(self.exe, ['-u', scriptFile])
        d = self.assertFailure(d, IOError)
        def cbFailed(err):
            return self.assertFailure(err.processEnded, error.ProcessDone)
        d.addCallback(cbFailed)
        return d 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:19,代碼來源:test_iutils.py

示例8: test_command_output_ends_with_truncation

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_command_output_ends_with_truncation(self):
        """After truncation, no further output is recorded."""
        factory = StubProcessFactory()
        self.plugin.process_factory = factory
        self.manager.config.script_output_limit = 1
        result = self.plugin.run_script("/bin/sh", "")

        # Ultimately we assert that the resulting output is limited to
        # 1024 bytes and indicates its truncation.
        result.addCallback(self.assertEqual,
                           ("x" * (1024 - 21)) + "\n**OUTPUT TRUNCATED**")
        protocol = factory.spawns[0][0]

        # Push 1024 bytes of output, so we trigger truncation.
        protocol.childDataReceived(1, b"x" * 1024)
        # Push 1024 bytes more
        protocol.childDataReceived(1, b"x" * 1024)

        for fd in (0, 1, 2):
            protocol.childConnectionLost(fd)
        protocol.processEnded(Failure(ProcessDone(0)))

        return result 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:25,代碼來源:test_scriptexecution.py

示例9: test_limit_time_accumulates_data

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_limit_time_accumulates_data(self):
        """
        Data from processes that time out should still be accumulated and
        available from the exception object that is raised.
        """
        factory = StubProcessFactory()
        self.plugin.process_factory = factory
        result = self.plugin.run_script("/bin/sh", "", time_limit=500)
        protocol = factory.spawns[0][0]
        protocol.makeConnection(DummyProcess())
        protocol.childDataReceived(1, b"hi\n")
        self.manager.reactor.advance(501)
        protocol.processEnded(Failure(ProcessDone(0)))

        def got_error(f):
            self.assertTrue(f.check(ProcessTimeLimitReachedError))
            self.assertEqual(f.value.data, "hi\n")

        result.addErrback(got_error)
        return result 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:22,代碼來源:test_scriptexecution.py

示例10: test_cancel_doesnt_blow_after_success

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_cancel_doesnt_blow_after_success(self):
        """
        When the process ends successfully and is immediately followed by the
        timeout, the output should still be in the failure and nothing bad will
        happen!
        [regression test: killing of the already-dead process would blow up.]
        """
        factory = StubProcessFactory()
        self.plugin.process_factory = factory
        result = self.plugin.run_script("/bin/sh", "", time_limit=500)
        protocol = factory.spawns[0][0]
        protocol.makeConnection(DummyProcess())
        protocol.childDataReceived(1, b"hi")
        protocol.processEnded(Failure(ProcessDone(0)))
        self.manager.reactor.advance(501)

        def got_result(output):
            self.assertEqual(output, "hi")

        result.addCallback(got_result)
        return result 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:23,代碼來源:test_scriptexecution.py

示例11: test_user

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_user(self):
        """A user can be specified in the message."""
        username = pwd.getpwuid(os.getuid())[0]
        uid, gid, home = get_user_info(username)

        def spawnProcess(protocol, filename, args, env, path, uid, gid):
            protocol.childDataReceived(1, "hi!\n")
            protocol.processEnded(Failure(ProcessDone(0)))
            self._verify_script(filename, sys.executable, "print 'hi'")

        process_factory = mock.Mock()
        process_factory.spawnProcess = mock.Mock(side_effect=spawnProcess)
        self.manager.add(
            ScriptExecutionPlugin(process_factory=process_factory))

        result = self._send_script(sys.executable, "print 'hi'", user=username)

        def check(_):
            process_factory.spawnProcess.assert_called_with(
                mock.ANY, mock.ANY, args=mock.ANY, uid=None, gid=None,
                path=mock.ANY, env=encoded_default_environment())

        return result.addCallback(check) 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:25,代碼來源:test_scriptexecution.py

示例12: test_restart_stops_exchanger

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_restart_stops_exchanger(self):
        """
        After a successful shutdown, the broker stops processing new messages.
        """
        message = {"type": "shutdown", "reboot": False, "operation-id": 100}
        self.plugin.perform_shutdown(message)

        [arguments] = self.process_factory.spawns
        protocol = arguments[0]
        protocol.processEnded(Failure(ProcessDone(status=0)))
        self.broker_service.reactor.advance(100)
        self.manager.reactor.advance(100)

        # New messages will not be exchanged after a reboot process is in
        # process.
        self.manager.broker.exchanger.schedule_exchange()
        payloads = self.manager.broker.exchanger._transport.payloads
        self.assertEqual(0, len(payloads))
        return protocol.result 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:21,代碼來源:test_shutdownmanager.py

示例13: test_readConnectionLost

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def test_readConnectionLost(self):
        """
        When stdin is closed and the protocol connected to it implements
        L{IHalfCloseableProtocol}, the protocol's C{readConnectionLost} method
        is called.
        """
        errorLogFile = self.mktemp()
        log.msg("Child process logging to " + errorLogFile)
        p = StandardIOTestProcessProtocol()
        p.onDataReceived = defer.Deferred()

        def cbBytes(ignored):
            d = p.onCompletion
            p.transport.closeStdin()
            return d
        p.onDataReceived.addCallback(cbBytes)

        def processEnded(reason):
            reason.trap(error.ProcessDone)
        d = self._requireFailure(p.onDataReceived, processEnded)

        self._spawnProcess(
            p, 'stdio_test_halfclose.py', errorLogFile)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:26,代碼來源:test_stdio.py

示例14: _getReason

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def _getReason(self, status):
        if status == 0:
            return error.ProcessDone(status)
        return error.ProcessTerminated(status) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:6,代碼來源:_dumbwin32proc.py

示例15: processEnded

# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ProcessDone [as 別名]
def processEnded(self, reason):
        """
        If the process ends with L{error.ProcessDone}, this method calls the
        L{IProtocol} provider's L{connectionLost} with a
        L{error.ConnectionDone}

        @see: L{ProcessProtocol.processEnded}
        """
        if (reason.check(error.ProcessDone) == error.ProcessDone) and (
                reason.value.status == 0):
            return self.protocol.connectionLost(
                Failure(error.ConnectionDone()))
        else:
            return self.protocol.connectionLost(reason) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:16,代碼來源:endpoints.py


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