本文整理汇总了Python中neubot.poller.POLLER.sched方法的典型用法代码示例。如果您正苦于以下问题:Python POLLER.sched方法的具体用法?Python POLLER.sched怎么用?Python POLLER.sched使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.poller.POLLER
的用法示例。
在下文中一共展示了POLLER.sched方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _waiting_rawtest
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _waiting_rawtest(self, stream, data):
''' Waiting for RAWTEST message from client '''
context = stream.opaque
context.bufferise(data)
tmp = context.pullup(len(RAWTEST))
if not tmp:
stream.recv(len(RAWTEST), self._waiting_rawtest)
return
if tmp[4:5] == PING_CODE:
logging.debug('< PING')
stream.send(PINGBACK, self._sent_pingback)
logging.debug('> PINGBACK')
return
if tmp[4:5] != RAWTEST_CODE:
raise RuntimeError('raw_srvr: received invalid message')
logging.debug('< RAWTEST')
logging.info('raw_srvr: waiting for RAWTEST message... complete')
logging.info('raw_srvr: raw test... in progress')
context.count = context.snap_count = stream.bytes_out
context.ticks = context.snap_ticks = utils.ticks()
context.snap_utime, context.snap_stime = os.times()[:2]
message = PIECE_CODE + context.auth * int(LEN_MESSAGE / AUTH_LEN)
context.message = struct.pack('!I', len(message)) + message
stream.send(context.message, self._piece_sent)
#logging.debug('> PIECE')
POLLER.sched(1, self._periodic, stream)
stream.recv(1, self._waiting_eof)
示例2: _periodic
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _periodic(self, args):
""" Periodically snap goodput """
stream = args[0]
if stream.opaque:
deferred = Deferred()
deferred.add_callback(self._periodic_internal)
deferred.add_errback(lambda err: self._periodic_error(stream, err))
deferred.callback(stream)
POLLER.sched(1, self._periodic, stream)
示例3: _schedule_after
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _schedule_after(self, interval):
''' Schedule next rendezvous after interval seconds '''
logging.info('background_rendezvous: next rendezvous in %d seconds',
interval)
timestamp = POLLER.sched(interval, self.run)
STATE.update('idle', publish=False)
STATE.update('next_rendezvous', timestamp)
示例4: _waiting_piece
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _waiting_piece(self, stream, data):
''' Invoked when new data is available '''
# Note: this loop cannot be adapted to process other messages
# easily, as pointed out in <skype_defs.py>.
context = stream.opaque
context.bufferise(data)
context.state['rcvr_data'].append((utils.ticks(), len(data)))
while True:
if context.left > 0:
context.left = context.skip(context.left)
if context.left > 0:
break
elif context.left == 0:
tmp = context.pullup(4)
if not tmp:
break
context.left, = struct.unpack('!I', tmp)
if context.left > MAXRECV:
raise RuntimeError('skype_clnt: PIECE too large')
if not context.ticks:
context.ticks = context.snap_ticks = utils.ticks()
context.count = context.snap_count = stream.bytes_in
context.snap_utime, context.snap_stime = os.times()[:2]
POLLER.sched(1, self._periodic, stream)
if context.left == 0:
logging.debug('< {empty-message}')
logging.info('skype_clnt: skype goodput test... complete')
ticks = utils.ticks()
timediff = ticks - context.ticks
bytesdiff = stream.bytes_in - context.count
context.state['goodput'] = {
'ticks': ticks,
'bytesdiff': bytesdiff,
'timediff': timediff,
}
if timediff > 1e-06:
speed = utils.speed_formatter(bytesdiff / timediff)
logging.info('skype_clnt: goodput: %s', speed)
STATE.update('test_download', speed, publish=0)
STATE.update('test_upload', 'N/A')
self._periodic_internal(stream)
context.state['complete'] = 1
stream.close()
return
else:
raise RuntimeError('skype_clnt: internal error')
stream.recv(MAXRECV, self._waiting_piece)
示例5: _periodic
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _periodic(self):
''' Periodically generate notification for old events '''
POLLER.sched(INTERVAL, self._periodic)
self._tofire, queue = [], self._tofire
for event in queue:
#
# WARNING! Please resist the temptation of merging
# the [] and the del into a single pop() because that
# will not work: this is a defaultdict and so here
# event might not be in _subscribers.
#
queue = self._subscribers[event]
del self._subscribers[event]
logging.debug("notify: periodically publish event: %s", event)
self._fireq(event, queue)
示例6: _waiting_piece
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _waiting_piece(self, stream, data):
""" Invoked when new data is available """
# Note: this loop cannot be adapted to process other messages
# easily, as pointed out in <raw_defs.py>.
context = stream.opaque
context.bufferise(data)
context.state["rcvr_data"].append((utils.ticks(), len(data)))
while True:
if context.left > 0:
context.left = context.skip(context.left)
if context.left > 0:
break
elif context.left == 0:
tmp = context.pullup(4)
if not tmp:
break
context.left, = struct.unpack("!I", tmp)
if context.left > MAXRECV:
raise RuntimeError("raw_clnt: PIECE too large")
if not context.ticks:
context.ticks = context.snap_ticks = utils.ticks()
context.count = context.snap_count = stream.bytes_in
context.snap_utime, context.snap_stime = os.times()[:2]
POLLER.sched(1, self._periodic, stream)
if context.left == 0:
logging.debug("< {empty-message}")
logging.info("raw_clnt: raw goodput test... complete")
ticks = utils.ticks()
timediff = ticks - context.ticks
bytesdiff = stream.bytes_in - context.count
context.state["goodput"] = {"ticks": ticks, "bytesdiff": bytesdiff, "timediff": timediff}
if timediff > 1e-06:
speed = utils.speed_formatter(bytesdiff / timediff)
logging.info("raw_clnt: goodput: %s", speed)
STATE.update("test_progress", "100%", publish=False)
STATE.update("test_download", speed, publish=0)
STATE.update("test_upload", "N/A")
self._periodic_internal(stream)
context.state["complete"] = 1
stream.close()
return
else:
raise RuntimeError("raw_clnt: internal error")
stream.recv(MAXRECV, self._waiting_piece)
示例7: _schedule_after
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _schedule_after(self, interval):
""" Schedule next rendezvous after interval seconds """
logging.info("background_rendezvous: next rendezvous in %d seconds", interval)
timestamp = POLLER.sched(interval, self.run)
STATE.update("idle", publish=False)
STATE.update("next_rendezvous", timestamp)
示例8: __init__
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def __init__(self):
self._timestamps = collections.defaultdict(int)
self._subscribers = collections.defaultdict(list)
self._tofire = []
POLLER.sched(INTERVAL, self._periodic)
示例9: _schedule
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _schedule(self):
''' Schedule next check for updates '''
interval = CONFIG['win32_updater_interval']
logging.debug('updater_runner: next check in %d seconds',
interval)
POLLER.sched(interval, self.retrieve_versioninfo)
示例10: _schedule
# 需要导入模块: from neubot.poller import POLLER [as 别名]
# 或者: from neubot.poller.POLLER import sched [as 别名]
def _schedule(self):
''' Schedule next check for updates '''
# TODO remember to raise this to 1800 seconds
POLLER.sched(60, self.retrieve_versioninfo)