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


Python HTTPConnectionPool.retryAutomatically方法代码示例

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


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

示例1: _getConnectionPool

# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import retryAutomatically [as 别名]
    def _getConnectionPool(self):
        pool = HTTPConnectionPool(reactor, self._persistent)

        if self._persistent:
            pool.maxPersistentPerHost = self._maxPersistentPerHost
            pool.cachedConnectionTimeout = self._cachedConnectionTimeout
            pool.retryAutomatically = self._retryAutomatically

        return pool
开发者ID:vesellov,项目名称:bitdust.devel,代码行数:11,代码来源:client.py

示例2: __init__

# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import retryAutomatically [as 别名]
    def __init__(self, hs):
        self.hs = hs
        self.signing_key = hs.config.signing_key[0]
        self.server_name = hs.hostname
        reactor = hs.get_reactor()
        pool = HTTPConnectionPool(reactor)
        pool.retryAutomatically = False
        pool.maxPersistentPerHost = 5
        pool.cachedConnectionTimeout = 2 * 60
        self.agent = Agent.usingEndpointFactory(
            reactor, MatrixFederationEndpointFactory(hs), pool=pool
        )
        self.clock = hs.get_clock()
        self._store = hs.get_datastore()
        self.version_string_bytes = hs.version_string.encode('ascii')
        self.default_timeout = 60

        def schedule(x):
            reactor.callLater(_EPSILON, x)

        self._cooperator = Cooperator(scheduler=schedule)
开发者ID:gergelypolonkai,项目名称:synapse,代码行数:23,代码来源:matrixfederationclient.py

示例3: dp5twistedclientFactory

# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import retryAutomatically [as 别名]
def dp5twistedclientFactory(state):
    global commonhttppool
    ## Build an async client
    cli = AsyncDP5Client(state)
    
    # Use a common pool of HTTPs connections
    if commonhttppool is None:
        httppool = HTTPConnectionPool(reactor, persistent=True)
        httppool.maxPersistentPerHost = 5
        httppool.retryAutomatically = False
    else:
        httppool = commonhttppool

    cli.pool = httppool
    cli.agent = Agent(reactor, pool=httppool)
    cli.inflight = 0

    ## Define the networking for registration
    def send_registration(cli, epoch, combined, msg, cb, xfail):
        if combined:
            ser = cli.state["combined"]["regServer"]
            surl = str("https://"+ser+"/register?epoch=%s" % (epoch-1))
        else:
            ser = cli.state["standard"]["regServer"]
            surl = str("https://" + ser + "/register?epoch=%s" % (epoch-1))

        cli.inflight += 1
        try:
            body = FileBodyProducer(StringIO(msg))

            d = cli.agent.request(
                'POST',
                surl,
                Headers({'User-Agent': ['DP5 Twisted Client']}),
                body)

            def err(*args):
                # print "REG ERROR", args
                # print args
                cli.inflight -= 1
                xfail(args[0])

            def cbRequest(response):
                finished = Deferred()
                finished.addCallback(cb)
                finished.addErrback(err)
                response.deliverBody(BufferedReception(finished))
                cli.inflight -= 1
                return finished

            d.addCallback(cbRequest)
            d.addErrback(err)
        except Exception as e:
            print e
            cli.inflight -= 1
            err(e)

    cli.register_handlers += [send_registration]

    ## Define the networking for lookups
    def send_lookup(cli, epoch, combined, seq, msg, cb, xfail):
        if msg == "":
            #print "No need to relay lookup"
            return cb("")

        if combined:
            ser = cli.state["combined"]["lookupServers"][seq]
            surl = str("https://"+ser+"/lookup?epoch=%s" % epoch)
        else:
            ser = cli.state["standard"]["lookupServers"][seq]
            surl = str("https://" + ser + "/lookup?epoch=%s" % epoch)

        cli.inflight += 1
        try:
            body = FileBodyProducer(StringIO(msg))

            d = cli.agent.request(
                'POST',
                surl,
                Headers({'User-Agent': ['DP5 Twisted Client']}),
                body)

            def err(*args):
                cli.inflight -= 1
                xfail(args[0])

            def cbRequest(response):
                finished = Deferred()
                finished.addCallback(cb)
                finished.addErrback(err)
                response.deliverBody(BufferedReception(finished))
                cli.inflight -= 1
                return finished
            
            d.addCallback(cbRequest)
            d.addErrback(err)
        except Exception as e:
            print e
            cli.inflight -= 1
            err(e)
#.........这里部分代码省略.........
开发者ID:haraldh,项目名称:dp5,代码行数:103,代码来源:dp5twistedclient.py

示例4: HTTPConnectionPool

# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import retryAutomatically [as 别名]
import random

import limits
limits.set_limits()

from users import User
import cPickle

SSLPOOL = True

## Common pool of HTTPs connection to
## ensure that SSL is not the bottle neck.
if SSLPOOL:
    commonhttppool = HTTPConnectionPool(reactor, persistent=True)
    commonhttppool.maxPersistentPerHost = 50
    commonhttppool.retryAutomatically = False
else:
    commonhttppool = None


class BufferedReception(Protocol):
    def __init__(self, finished):
        self.finished = finished
        self.bytes = None

    def dataReceived(self, bytes):        
        if self.bytes == None:
            self.bytes = StringIO()
        self.bytes.write(bytes)

    def connectionLost(self, reason):
开发者ID:haraldh,项目名称:dp5,代码行数:33,代码来源:dp5twistedclient.py


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