当前位置: 首页>>代码示例>>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;未经允许,请勿转载。