本文整理汇总了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
示例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()
示例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()
示例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
示例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
示例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()
示例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)
示例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)
示例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)