本文整理汇总了Python中tornado.ioloop.PeriodicCallback.callback方法的典型用法代码示例。如果您正苦于以下问题:Python PeriodicCallback.callback方法的具体用法?Python PeriodicCallback.callback怎么用?Python PeriodicCallback.callback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.ioloop.PeriodicCallback
的用法示例。
在下文中一共展示了PeriodicCallback.callback方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startBeat
# 需要导入模块: from tornado.ioloop import PeriodicCallback [as 别名]
# 或者: from tornado.ioloop.PeriodicCallback import callback [as 别名]
def startBeat(self, connection, request_handler):
beater = PeriodicCallback(None, self.heart_interval, IOLoop.instance())
def _beat():
if connection.connected is False:
beater.stop()
else:
request_handler.write(chr(messaging.StreamingMessage.NULL_BYTE))
request_handler.flush()
beater.callback = _beat
beater.start()
示例2: startStream
# 需要导入模块: from tornado.ioloop import PeriodicCallback [as 别名]
# 或者: from tornado.ioloop.PeriodicCallback import callback [as 别名]
def startStream(self, msg, request_handler):
"""Get this stream rolling!"""
connection = self.channel_set.connection_manager.getConnection(msg.headers.get(msg.FLEX_CLIENT_ID_HEADER))
if self.channel_set.notify_connections is True:
poller = None
else:
# Call _notify multiple times if polling.
poller = PeriodicCallback(None, self.poll_interval, IOLoop.instance())
# Handle new message.
def _notify():
if connection.connected is False:
if poller is not None:
poller.stop()
connection.unSetNotifyFunc()
if request_handler.request.connection.stream.closed() is False:
msg = messaging.StreamingMessage.getDisconnectMsg()
self.sendMsgs((msg,), request_handler)
request_handler.finish()
return
msgs = self.channel_set.subscription_manager.pollConnection(connection)
if len(msgs) > 0:
self.sendMsgs(msgs, request_handler)
connection.setNotifyFunc(_notify)
if poller is not None:
poller.callback = _notify
poller.start()
# Handle dropped connection.
def _connectionLost():
if poller is not None:
poller.stop()
self.channel_set.disconnect(connection)
connection.unSetNotifyFunc()
request_handler.request.connection.stream.set_close_callback(_connectionLost)
# Send acknowledge message
response = msg.acknowledge()
response.body = connection.id
self.sendMsgs((response,), request_handler)
request_handler.write(chr(messaging.StreamingMessage.NULL_BYTE) * self.KICKSTART_BYTES)
request_handler.flush()
self.startBeat(connection, request_handler)
示例3: _pollForMessage
# 需要导入模块: from tornado.ioloop import PeriodicCallback [as 别名]
# 或者: from tornado.ioloop.PeriodicCallback import callback [as 别名]
def _pollForMessage(self, packet, message, connection):
"""Overridden to be non-blocking."""
request = self.setupPollRequest(packet)
# Polls for messages every self.poll_interval
poller = PeriodicCallback(None, self.poll_interval, IOLoop.instance())
def _timeout():
# Executed when timeout is reached.
poller.stop()
messages = self.channel_set.subscription_manager.pollConnection(connection)
self.finishPoll(request, packet, message, messages)
if self.wait_interval > -1:
timeout_call = IOLoop.instance().add_timeout(
time.time() + self.wait_interval, _timeout)
else:
timeout_call = None
# Timeout if client drops connection.
request.request.connection.stream.set_close_callback(_timeout)
def _poll():
messages = self.channel_set.subscription_manager.pollConnection(connection)
if len(messages) > 0:
poller.stop()
if timeout_call is not None:
# Disable time out callback
IOLoop.instance().remove_timeout(timeout_call)
self.finishPoll(request, packet, message, messages)
poller.callback = _poll
poller.start()
return ()