当前位置: 首页>>代码示例>>Python>>正文


Python error.TimeoutError方法代码示例

本文整理汇总了Python中twisted.internet.error.TimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python error.TimeoutError方法的具体用法?Python error.TimeoutError怎么用?Python error.TimeoutError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.error的用法示例。


在下文中一共展示了error.TimeoutError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: errback_httpbin

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def errback_httpbin(self, failure):
		# log all failures
		self.logger.error(repr(failure))

		# in case you want to do something special for some errors,
		# you may need the failure's type:
		if failure.check(HttpError):
			# these exceptions come from HttpError spider middleware
			# you can get the non-200 response
			response = failure.value.response
			self.logger.error('HttpError on %s', response.url)

		elif failure.check(DNSLookupError):
			# this is the original request
			request = failure.request
			self.logger.error('DNSLookupError on %s', request.url)

		elif failure.check(TimeoutError, TCPTimedOutError):
			request = failure.request
			self.logger.error('TimeoutError on %s', request.url) 
开发者ID:czs0x55aa,项目名称:video_url_crawler_demo,代码行数:22,代码来源:aiqiyi_spider.py

示例2: test_serverTimeout

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def test_serverTimeout(self):
        """
        The *client* has a timeout mechanism which will close connections that
        are inactive for a period.
        """
        c = Clock()
        self.server.timeoutTest = True
        self.client.timeout = 5 #seconds
        self.client.callLater = c.callLater
        self.selectedArgs = None

        def login():
            d = self.client.login(b'testuser', b'password-test')
            c.advance(5)
            d.addErrback(timedOut)
            return d

        def timedOut(failure):
            self._cbStopClient(None)
            failure.trap(error.TimeoutError)

        d = self.connected.addCallback(strip(login))
        d.addErrback(self._ebGeneral)
        return defer.gatherResults([d, self.loopback()]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_imap.py

示例3: _process_error

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def _process_error(self, failure):
        err = failure.value
        if isinstance(err, gcmclient.GCMAuthenticationError):
            self.log.error("GCM Authentication Error: %s" % err)
            raise RouterException("Server error", status_code=500,
                                  errno=901)
        if isinstance(err, TimeoutError):
            self.log.warn("GCM Timeout: %s" % err)
            self.metrics.increment("notification.bridge.error",
                                   tags=make_tags(
                                       self._base_tags,
                                       reason="timeout"))
            raise RouterException("Server error", status_code=502,
                                  errno=903,
                                  log_exception=False)
        if isinstance(err, ConnectError):
            self.log.warn("GCM Unavailable: %s" % err)
            self.metrics.increment("notification.bridge.error",
                                   tags=make_tags(
                                       self._base_tags,
                                       reason="connection_unavailable"))
            raise RouterException("Server error", status_code=502,
                                  errno=902,
                                  log_exception=False)
        return failure 
开发者ID:mozilla-services,项目名称:autopush,代码行数:27,代码来源:gcm.py

示例4: errback_httpbin

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def errback_httpbin(self, failure):
        # log all failures
        self.logger.error(repr(failure))

        # in case you want to do something special for some errors,
        # you may need the failure's type:

        if failure.check(HttpError):
            print("HttpError出错了")
            # these exceptions come from HttpError spider middleware
            # you can get the non-200 response
            response = failure.value.response
            self.logger.error('HttpError on %s', response.url)

        elif failure.check(DNSLookupError):
            # this is the original request
            request = failure.request
            self.logger.error('DNSLookupError on %s', request.url)

        elif failure.check(TimeoutError, TCPTimedOutError):
            request = failure.request
            self.logger.error('TimeoutError on %s', request.url) 
开发者ID:xugongli,项目名称:poi_spider,代码行数:24,代码来源:test_errorback.py

示例5: connectionLost

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def connectionLost(self, reason):
        if self.timeout > 0:
            self.setTimeout(None)

        if self._timedOut:
            reason = error.TimeoutError()
        elif self._greetingError:
            reason = ServerErrorResponse(self._greetingError)

        d = []
        if self._waiting is not None:
            d.append(self._waiting)
            self._waiting = None
        if self._blockedQueue is not None:
            d.extend([deferred for (deferred, f, a) in self._blockedQueue])
            self._blockedQueue = None
        for w in d:
            w.errback(reason) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:pop3client.py

示例6: test_serverTimeout

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def test_serverTimeout(self):
        """
        The *client* has a timeout mechanism which will close connections that
        are inactive for a period.
        """
        c = Clock()
        self.server.timeoutTest = True
        self.client.timeout = 5 #seconds
        self.client.callLater = c.callLater
        self.selectedArgs = None

        def login():
            d = self.client.login('testuser', 'password-test')
            c.advance(5)
            d.addErrback(timedOut)
            return d

        def timedOut(failure):
            self._cbStopClient(None)
            failure.trap(error.TimeoutError)

        d = self.connected.addCallback(strip(login))
        d.addErrback(self._ebGeneral)
        return defer.gatherResults([d, self.loopback()]) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:test_imap.py

示例7: testCallBeforeStartupUnexecuted

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testCallBeforeStartupUnexecuted(self):
        progname = self.mktemp()
        progfile = file(progname, 'w')
        progfile.write(_callBeforeStartupProgram % {'reactor': reactor.__module__})
        progfile.close()

        def programFinished((out, err, reason)):
            if reason.check(error.ProcessTerminated):
                self.fail("Process did not exit cleanly (out: %s err: %s)" % (out, err))

            if err:
                log.msg("Unexpected output on standard error: %s" % (err,))
            self.failIf(out, "Expected no output, instead received:\n%s" % (out,))

        def programTimeout(err):
            err.trap(error.TimeoutError)
            proto.signalProcess('KILL')
            return err

        env = os.environ.copy()
        env['PYTHONPATH'] = os.pathsep.join(sys.path)
        d = defer.Deferred().addCallbacks(programFinished, programTimeout)
        proto = ThreadStartupProcessProtocol(d)
        reactor.spawnProcess(proto, sys.executable, ('python', progname), env)
        return d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:test_threads.py

示例8: testServerTimeout

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testServerTimeout(self):
        self.server.timeoutTest = True
        self.client.timeout = 5 #seconds
        self.selectedArgs = None

        def login():
            d = self.client.login('testuser', 'password-test')
            d.addErrback(timedOut)
            return d

        def timedOut(failure):
            self._cbStopClient(None)
            failure.trap(error.TimeoutError)

        d = self.connected.addCallback(strip(login))
        d.addErrback(self._ebGeneral)
        self.loopback() 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:19,代码来源:test_imap.py

示例9: handleCmdConnectFailure

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def handleCmdConnectFailure(self, failure):
        log.error("CMD CONNECT: %s" % failure.getErrorMessage())

        # Map common twisted errors to SOCKS error codes
        if failure.type == error.NoRouteError:
            self.sendReply(SOCKSv5Reply.NetworkUnreachable)
        elif failure.type == error.ConnectionRefusedError:
            self.sendReply(SOCKSv5Reply.ConnectionRefused)
        elif failure.type == error.TCPTimedOutError or failure.type == error.TimeoutError:
            self.sendReply(SOCKSv5Reply.TTLExpired)
        elif failure.type == error.UnsupportedAddressFamily:
            self.sendReply(SOCKSv5Reply.AddressTypeNotSupported)
        elif failure.type == error.ConnectError:
            # Twisted doesn't have a exception defined for EHOSTUNREACH,
            # so the failure is a ConnectError.  Try to catch this case
            # and send a better reply, but fall back to a GeneralFailure.
            reply = SOCKSv5Reply.GeneralFailure
            try:
                import errno
                if hasattr(errno, "EHOSTUNREACH"):
                    if failure.value.osError == errno.EHOSTUNREACH:
                        reply = SOCKSv5Reply.HostUnreachable
                if hasattr(errno, "WSAEHOSTUNREACH"):
                    if failure.value.osError == errno.WSAEHOSTUNREACH:
                        reply = SOCKSv5Reply.HostUnreachable
            except Exception:
                pass
            self.sendReply(reply)
        else:
            self.sendReply(SOCKSv5Reply.GeneralFailure)

        failure.trap(error.NoRouteError, error.ConnectionRefusedError,
                     error.TCPTimedOutError, error.TimeoutError,
                     error.UnsupportedAddressFamily, error.ConnectError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:socks5.py

示例10: connect

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def connect(self):
        """Start connection to remote server."""
        if self.state != "disconnected":
            raise RuntimeError("can't connect in this state")

        self.state = "connecting"
        if not self.factoryStarted:
            self.factory.doStart()
            self.factoryStarted = 1
        self.transport = transport = self._makeTransport()
        if self.timeout is not None:
            self.timeoutID = self.reactor.callLater(self.timeout, transport.failIfNotConnected, error.TimeoutError())
        self.factory.startedConnecting(self) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:base.py

示例11: connectionLost

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def connectionLost(self, reason):
        """
        Clean up when the connection has been lost.

        When the loss of connection was initiated by the client due to a
        timeout, the L{_timedOut} flag will be set.  When it was initiated by
        the client due to an error in the server greeting, L{_greetingError}
        will be set to the server response minus the status indicator.

        @type reason: L{Failure <twisted.python.failure.Failure>}
        @param reason: The reason the connection was terminated.
        """
        if self.timeout > 0:
            self.setTimeout(None)

        if self._timedOut:
            reason = error.TimeoutError()
        elif self._greetingError:
            reason = ServerErrorResponse(self._greetingError)

        d = []
        if self._waiting is not None:
            d.append(self._waiting)
            self._waiting = None
        if self._blockedQueue is not None:
            d.extend([deferred for (deferred, f, a) in self._blockedQueue])
            self._blockedQueue = None
        for w in d:
            w.errback(reason) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:pop3client.py

示例12: testTimeout

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testTimeout(self):
        def login():
            d = self.client.login('test', 'twisted')
            d.addCallback(loggedIn)
            d.addErrback(timedOut)
            return d

        def loggedIn(result):
            self.fail("Successfully logged in!?  Impossible!")


        def timedOut(failure):
            failure.trap(error.TimeoutError)
            self._cbStopClient(None)

        def quit():
            return self.client.quit()

        self.client.timeout = 0.01

        # Tell the server to not return a response to client.  This
        # will trigger a timeout.
        pop3testserver.TIMEOUT_RESPONSE = True

        methods = [login, quit]
        map(self.connected.addCallback, map(strip, methods))
        self.connected.addCallback(self._cbStopClient)
        self.connected.addErrback(self._ebGeneral)
        return self.loopback() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:test_pop3client.py

示例13: _reissue

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def _reissue(self, reason, addressesLeft, addressesUsed, query, timeout):
        reason.trap(dns.DNSQueryTimeoutError)

        # If there are no servers left to be tried, adjust the timeout
        # to the next longest timeout period and move all the
        # "used" addresses back to the list of addresses to try.
        if not addressesLeft:
            addressesLeft = addressesUsed
            addressesLeft.reverse()
            addressesUsed = []
            timeout = timeout[1:]

        # If all timeout values have been used this query has failed.  Tell the
        # protocol we're giving up on it and return a terminal timeout failure
        # to our caller.
        if not timeout:
            return failure.Failure(defer.TimeoutError(query))

        # Get an address to try.  Take it out of the list of addresses
        # to try and put it ino the list of already tried addresses.
        address = addressesLeft.pop()
        addressesUsed.append(address)

        # Issue a query to a server.  Use the current timeout.  Add this
        # function as a timeout errback in case another retry is required.
        d = self._query(address, query, timeout[0], reason.value.id)
        d.addErrback(self._reissue, addressesLeft, addressesUsed, query, timeout)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:30,代码来源:client.py

示例14: _timeoutZone

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def _timeoutZone(self, d, controller, connector, seconds):
        connector.disconnect()
        controller.timeoutCall = None
        controller.deferred = None
        d.errback(error.TimeoutError("Zone lookup timed out after %d seconds" % (seconds,))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:client.py

示例15: testCallBeforeStartupUnexecuted

# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testCallBeforeStartupUnexecuted(self):
        progname = self.mktemp()
        with open(progname, 'w') as progfile:
            progfile.write(_callBeforeStartupProgram % {'reactor': reactor.__module__})

        def programFinished(result):
            (out, err, reason) = result
            if reason.check(error.ProcessTerminated):
                self.fail("Process did not exit cleanly (out: %s err: %s)" % (out, err))

            if err:
                log.msg("Unexpected output on standard error: %s" % (err,))
            self.assertFalse(
                out,
                "Expected no output, instead received:\n%s" % (out,))

        def programTimeout(err):
            err.trap(error.TimeoutError)
            proto.signalProcess('KILL')
            return err

        env = os.environ.copy()
        env['PYTHONPATH'] = os.pathsep.join(sys.path)
        d = defer.Deferred().addCallbacks(programFinished, programTimeout)
        proto = ThreadStartupProcessProtocol(d)
        reactor.spawnProcess(proto, sys.executable, ('python', progname), env)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:29,代码来源:test_threads.py


注:本文中的twisted.internet.error.TimeoutError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。