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


Python policies.TimeoutMixin方法代码示例

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


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

示例1: buildProtocol

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def buildProtocol(self, addr):
        p = protocol.ServerFactory.buildProtocol(self, addr)
        # timeOut needs to be on the Protocol instance cause
        # TimeoutMixin expects it there
        p.timeOut = self.timeOut
        return p 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:http.py

示例2: timeoutConnection

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def timeoutConnection(self):
        """
        Called when the connection has been inactive for
        L{self.timeOut<twisted.protocols.policies.TimeoutMixin.timeOut>}
        seconds. Cleanly tears the connection down, attempting to notify the
        peer if needed.

        We override this method to add two extra bits of functionality:

         - We want to log the timeout.
         - We want to send a GOAWAY frame indicating that the connection is
           being terminated, and whether it was clean or not. We have to do this
           before the connection is torn down.
        """
        self._log.info(
            "Timing out client {client}", client=self.transport.getPeer()
        )

        # Check whether there are open streams. If there are, we're going to
        # want to use the error code PROTOCOL_ERROR. If there aren't, use
        # NO_ERROR.
        if (self.conn.open_outbound_streams > 0 or
                self.conn.open_inbound_streams > 0):
            error_code = h2.errors.PROTOCOL_ERROR
        else:
            error_code = h2.errors.NO_ERROR

        self.conn.close_connection(error_code=error_code)
        self.transport.write(self.conn.data_to_send())

        # We're done, throw the connection away.
        self.transport.loseConnection() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:34,代码来源:_http2.py

示例3: timeoutConnection

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def timeoutConnection(self):
        self._log.info(
            "Timing out client: {peer}",
            peer=str(self.transport.getPeer())
        )
        if self.abortTimeout is not None:
            # We use self.callLater because that's what TimeoutMixin does.
            self._abortingCall = self.callLater(
                self.abortTimeout, self.forceAbortClient
            )
        self.loseConnection() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:13,代码来源:http.py

示例4: callLater

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def callLater(self):
        """
        A value for the C{callLater} callback. This callback is used by the
        L{twisted.protocols.policies.TimeoutMixin} to handle timeouts.
        """
        return self._channel.callLater 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:8,代码来源:http.py

示例5: buildProtocol

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def buildProtocol(self, addr):
        p = protocol.ServerFactory.buildProtocol(self, addr)

        # This is a bit of a hack to ensure that the HTTPChannel timeouts
        # occur on the same reactor as the one we're using here. This could
        # ideally be resolved by passing the reactor more generally to the
        # HTTPChannel, but that won't work for the TimeoutMixin until we fix
        # https://twistedmatrix.com/trac/ticket/8488
        p.callLater = self._reactor.callLater

        # timeOut needs to be on the Protocol instance cause
        # TimeoutMixin expects it there
        p.timeOut = self.timeOut
        return p 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:16,代码来源:http.py

示例6: timeoutConnection

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def timeoutConnection(self):
        """
        Called when the connection has been inactive for
        L{self.timeOut<twisted.protocols.policies.TimeoutMixin.timeOut>}
        seconds. Cleanly tears the connection down, attempting to notify the
        peer if needed.

        We override this method to add two extra bits of functionality:

         - We want to log the timeout.
         - We want to send a GOAWAY frame indicating that the connection is
           being terminated, and whether it was clean or not. We have to do this
           before the connection is torn down.
        """
        self._log.info(
            "Timing out client {client}", client=self.transport.getPeer()
        )

        # Check whether there are open streams. If there are, we're going to
        # want to use the error code PROTOCOL_ERROR. If there aren't, use
        # NO_ERROR.
        if (self.conn.open_outbound_streams > 0 or
                self.conn.open_inbound_streams > 0):
            error_code = h2.errors.ErrorCodes.PROTOCOL_ERROR
        else:
            error_code = h2.errors.ErrorCodes.NO_ERROR

        self.conn.close_connection(error_code=error_code)
        self.transport.write(self.conn.data_to_send())

        # Don't let the client hold this connection open too long.
        if self.abortTimeout is not None:
            # We use self.callLater because that's what TimeoutMixin does, even
            # though we have a perfectly good reactor sitting around. See
            # https://twistedmatrix.com/trac/ticket/8488.
            self._abortingCall = self.callLater(
                self.abortTimeout, self.forceAbortClient
            )

        # We're done, throw the connection away.
        self.transport.loseConnection() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:43,代码来源:_http2.py

示例7: timeoutConnection

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def timeoutConnection(self):
        # log.info("Timing out client: %s" % str(self.transport.getPeer()))
        # Set an abort timer in case an orderly close hangs
        self._abortTimer = reactor.callLater(self.closeTimeOut, self._abortTimeout)
        policies.TimeoutMixin.timeoutConnection(self) 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:7,代码来源:http.py

示例8: timeoutConnection

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def timeoutConnection(self):
        log.msg("Timing out client: %s" % str(self.transport.getPeer()))
        policies.TimeoutMixin.timeoutConnection(self) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:5,代码来源:http.py

示例9: testOverriddenCallLater

# 需要导入模块: from twisted.protocols import policies [as 别名]
# 或者: from twisted.protocols.policies import TimeoutMixin [as 别名]
def testOverriddenCallLater(self):
        """
        Test that setting callLater on a subclass of TimeoutMixin causes the
        protocol to use that callable instead of C{reactor.callLater}.
        """
        calls = []
        p = TimeoutTester()
        p.callLater = lambda *a, **kw: calls.append((a, kw))
        p.setTimeout(10)
        self.assertEquals(len(calls), 1) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:12,代码来源:test_policies.py


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