本文整理汇总了Python中twisted.internet.task.LoopingCall.stop方法的典型用法代码示例。如果您正苦于以下问题:Python LoopingCall.stop方法的具体用法?Python LoopingCall.stop怎么用?Python LoopingCall.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.task.LoopingCall
的用法示例。
在下文中一共展示了LoopingCall.stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: myApp
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class myApp(App):
'''a simple app'''
def __init__(self, reactor):
self.menu = [('&start', self.start),
('sto&p', self.stop),
('&quit', self.quit)]
App.__init__(self, reactor, 'Simple App', self.menu)
def start_clock(self):
self.__i__ = 0
self.__lc = LoopingCall(self.clock)
self.__lc.start(1.0)
def clock(self):
log.msg("clock", self.__i__)
self.widget('table').set_cells([(0, 0, self.__i__)])
self.widget('table').draw()
self.__i__ += 1
def start(self, key):
log.msg("menu: start", key)
def stop(self, key):
self.__lc.stop()
log.msg("menu: stop", key)
def list_box_active_item_changed(self, arg):
'''test callback,
here, we just add the callback to other listbox
'''
self.widget('table').set_cells([(1, 2, arg['active'])])
self.widget('table').draw()
示例2: Pinger
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class Pinger(object):
"""
An periodic AMP ping helper.
"""
def __init__(self, reactor):
"""
:param IReactorTime reactor: The reactor to use to schedule the pings.
"""
self.reactor = reactor
def start(self, protocol, interval):
"""
Start sending some pings.
:param AMP protocol: The protocol over which to send the pings.
:param timedelta interval: The interval at which to send the pings.
"""
def ping():
protocol.callRemote(NoOp)
self._pinging = LoopingCall(ping)
self._pinging.clock = self.reactor
self._pinging.start(interval.total_seconds(), now=False)
def stop(self):
"""
Stop sending the pings.
"""
self._pinging.stop()
示例3: PollingDataStream
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class PollingDataStream(DataStream):
""" A self-polling data stream.
This class represents a data stream that wakes up at a given frequency,
and calls the :meth:`poll` method.
"""
frequency = None # Either a timedelta object, or the number of seconds
now = False
def __init__(self):
super(PollingDataStream, self).__init__()
self.timer = LoopingCall(self.poll)
if isinstance(self.frequency, timedelta):
seconds = (
self.frequency.seconds
+ (self.frequency.days * 24 * 60 * 60)
+ (self.frequency.microseconds / 1000000.0)
)
else:
seconds = self.frequency
log.debug("Setting a %s second timer" % seconds)
self.timer.start(seconds, now=self.now)
def poll(self):
raise NotImplementedError
def stop(self):
super(PollingDataStream, self).stop()
try:
if hasattr(self, "timer"):
self.timer.stop()
except Exception, e:
self.log.warn(e)
示例4: SendsManyFileDescriptors
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class SendsManyFileDescriptors(ConnectableProtocol):
paused = False
def connectionMade(self):
self.socket = socket()
self.transport.registerProducer(self, True)
def sender():
self.transport.sendFileDescriptor(self.socket.fileno())
self.transport.write(b"x")
self.task = LoopingCall(sender)
self.task.clock = self.transport.reactor
self.task.start(0).addErrback(err, "Send loop failure")
def stopProducing(self):
self._disconnect()
def resumeProducing(self):
self._disconnect()
def pauseProducing(self):
self.paused = True
self.transport.unregisterProducer()
self._disconnect()
def _disconnect(self):
self.task.stop()
self.transport.abortConnection()
self.other.transport.abortConnection()
示例5: PeriodicTasksService
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class PeriodicTasksService(Service):
def __init__(self, clock, taskFunction, interval=60):
self.clock = clock
self.taskFunction = taskFunction
self.interval = interval
self._delayedCall = None
self._looper = None
self._loopFinished = None
def startService(self):
Service.startService(self)
now = time.time()
startDelta = now // self.interval * self.interval + self.interval - now
self._delayedCall = self.clock.callLater(startDelta, self._startLooping)
def _startLooping(self):
self._delayedCall = None
self._looper = LoopingCall(self._call)
self._looper.clock = self.clock
self._loopFinished = self._looper.start(self.interval)
def _call(self):
d = deferToThread(self.taskFunction)
d.addErrback(log.err, "error calling periodic tasks")
return d
def stopService(self):
if self._delayedCall:
self._delayedCall.cancel()
self._delayedCall = None
return
self._looper.stop()
self._loopFinished.addCallback(lambda _: Service.stopService(self))
return self._loopFinished
示例6: CacheService
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class CacheService(Service):
def __init__(self, *args, **kwargs):
self.call = None
self.node_updater = NodeCacheUpdater()
self.cluster_updater = ClusterCacheUpdater()
self.vm_updater = VirtualMachineCacheUpdater()
self.job_updater = JobCacheUpdater()
def update_cache(self):
""" a single run of all update classes """
return DeferredList(
[
self.vm_updater.update(),
self.job_updater.update(),
self.node_updater.update(),
self.cluster_updater.update(),
]
)
def startService(self):
self.call = LoopingCall(self.update_cache)
self.call.start(settings.PERIODIC_CACHE_REFRESH)
def stopService(self):
if self.call is not None:
self.call.stop()
示例7: ICUMonitorFactory
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class ICUMonitorFactory(protocol.ClientFactory):
def __init__(self, gui_msg_callback, gui_ip, gui_port):
self.ip = gui_ip
self.port = gui_port
self.msg_callback = gui_msg_callback
self.objmonit = None
def buildProtocol(self, addr):
return ICUMonitor(self.msg_callback)
def clientConnectionLost(self, connector, reason):
pass
def clientConnectionFailed(self, connector, reason):
pass
def sendmsg(self, gui_reactor):
gui_reactor.connectTCP(self.ip, self.port, self)
def startsend(self, gui_reactor, timerep):
self.loop = LoopingCall(self.sendmsg, gui_reactor)
self.loop.start(timerep)
def stopsend(self):
self.loop.stop()
示例8: EnvisalinkClientFactory
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class EnvisalinkClientFactory(ReconnectingClientFactory):
# we will only ever have one connection to envisalink at a time
envisalinkClient = None
_currentLoopingCall = None
def __init__(self, config):
self._config = config
def buildProtocol(self, addr):
logging.debug("%s connection estblished to %s:%s", addr.type, addr.host, addr.port)
logging.debug("resetting connection delay")
self.resetDelay()
self.envisalinkClient = EnvisalinkClient(self._config)
# check on the state of the envisalink connection repeatedly
self._currentLoopingCall = LoopingCall(self.envisalinkClient.check_alive)
self._currentLoopingCall.start(1)
return self.envisalinkClient
def startedConnecting(self, connector):
logging.debug("Started to connect to Envisalink...")
def clientConnectionLost(self, connector, reason):
logging.debug('Lost connection to Envisalink. Reason: %s', str(reason))
self._currentLoopingCall.stop()
ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):
logging.debug('Connection failed to Envisalink. Reason: %s', str(reason))
self._currentLoopingCall.stop()
ReconnectingClientFactory.clientConnectionFailed(self, connector,
reason)
示例9: VOEventBroadcasterFactory
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class VOEventBroadcasterFactory(ServerFactory):
IAMALIVE_INTERVAL = 60 # Sent iamalive every IAMALIVE_INTERVAL seconds
protocol = VOEventBroadcaster
def __init__(self, local_ivo, test_interval):
# test_interval is the time in seconds between sending test events to
# the network. 0 to disable.
self.local_ivo = local_ivo
self.test_interval = test_interval
self.broadcasters = []
self.alive_loop = LoopingCall(self.sendIAmAlive)
self.test_loop = LoopingCall(self.sendTestEvent)
def startFactory(self):
self.alive_loop.start(self.IAMALIVE_INTERVAL)
if self.test_interval:
self.test_loop.start(self.test_interval)
return ServerFactory.startFactory(self)
def stopFactory(self):
self.alive_loop.stop()
if self.test_loop.running:
self.test_loop.stop()
return ServerFactory.stopFactory(self)
def sendIAmAlive(self):
log.debug("Broadcasting iamalive")
for broadcaster in self.broadcasters:
broadcaster.sendIAmAlive()
def sendTestEvent(self):
log.debug("Broadcasting test event")
test_event = broker_test_message(self.local_ivo)
for broadcaster in self.broadcasters:
broadcaster.send_event(test_event)
示例10: Autofetcher
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class Autofetcher(object):
"""
Download name claims as they occur
"""
def __init__(self, api):
self._api = api
self._checker = LoopingCall(self._check_for_new_claims)
self.best_block = None
def start(self):
reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
self._checker.start(5)
def stop(self):
log.info("Stopping autofetcher")
self._checker.stop()
def _check_for_new_claims(self):
block = self._api.get_best_blockhash()
if block != self.best_block:
log.info("Checking new block for name claims, block hash: %s" % block)
self.best_block = block
transactions = self._api.get_block({'blockhash': block})['tx']
for t in transactions:
c = self._api.get_claims_for_tx({'txid': t})
if len(c):
for i in c:
log.info("Downloading stream for claim txid: %s" % t)
self._api.get({'name': t, 'stream_info': json.loads(i['value'])})
示例11: FileConsumer
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class FileConsumer(object):
_looper = None
_producer = None
def __init__(self, reactor=None, interval=0.01):
self._reactor = reactor
self._interval = interval
self._io = StringIO()
def registerProducer(self, producer, isPush):
if not isPush and not self._reactor:
raise ValueError("can't read from a pull producer with no reactor")
self._producer = producer
if not isPush:
self._looper = LoopingCall(self._pull)
self._looper.clock = self._reactor
self._looper.start(self._interval, now=False)
def unregisterProducer(self):
self._producer = None
if self._looper:
self._looper.stop()
def _pull(self):
self._producer.resumeProducing()
def write(self, data):
self._io.write(data)
def value(self):
return self._io.getvalue()
示例12: TimeOnlineLabel
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class TimeOnlineLabel(gtk.Label):
"""A display of how long the current session has been online for."""
def __init__(self):
gtk.Label.__init__(self)
self.looping_call = LoopingCall(self.update_time)
self.start_time = None
def start_counting(self):
"""Start ticking."""
self.start_time = datetime.now()
#don't leave our display blank
self.update_time()
self.looping_call.start(0.5) #update it twice per second
def stop_counting(self):
"""We only count time online; stop counting."""
self.looping_call.stop()
def update_time(self):
"""Should tick once a second. Displays the current running count of
how long's been spent online.
"""
delta = datetime.now() - self.start_time
#chop off microseconds, for neatness
delta = timedelta(delta.days, delta.seconds)
self.set_text('Time online: %s' % delta)
示例13: RelayProtocol
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class RelayProtocol(RTMProtocol):
clock = reactor
def __init__(self, session_data):
RTMProtocol.__init__(self)
self.session_data = session_data
self.bot_user_id = session_data['self']['id']
self.lc = None
self.relay = None
def onOpen(self):
self.relay = self.factory.relay
self.lc = LoopingCall(self.send_ping)
self.lc.clock = self.clock
self.lc.start(3, now=True)
def onClose(self, wasClean, code, reason):
if self.relay is not None:
self.relay.remove_protocol(self.bot_user_id)
if self.lc is not None:
self.lc.stop()
def onMessage(self, payload, isBinary):
data = json.loads(payload)
self.relay.relay(self.bot_user_id, data)
def send_ping(self):
return self.send_message({
"type": "ping",
})
def send_message(self, data):
return self.sendMessage(json.dumps(data))
示例14: Blinker
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class Blinker(object):
def __init__(self, port, interval=0.5):
self.port = port
self.interval = interval
self.state = None
self.transition = None
def set(self, *args, **kwargs):
self.blink()
def unset(self):
self.transition_stop()
self.port.unset()
def blink(self):
self.transition_stop()
self.transition = LoopingCall(self.blink_task)
self.transition.start(self.interval)
def transition_stop(self):
if self.transition and self.transition.running:
self.transition.stop()
def blink_task(self):
if self.state:
self.state = False
self.port.set()
else:
self.state = True
self.port.unset()
示例15: __init__
# 需要导入模块: from twisted.internet.task import LoopingCall [as 别名]
# 或者: from twisted.internet.task.LoopingCall import stop [as 别名]
class IconAnimator:
lc = None
def __init__(self, box, icons):
self.box = box
self.icons = icons
for icon in icons:
icon.show()
self.stop()
def tick(self):
self.position += 1
self.position %= len(self.icons)
c = self.box.get_children()
if c:
self.box.remove(c[0])
self.box.add(self.icons[self.position])
def start(self):
self.animating = True
self.tick()
self.lc = LoopingCall(self.tick)
self.lc.start(1.0)
def stop(self, index=0):
self.animating = False
self.position = index - 1
self.tick()
if self.lc is not None:
self.lc.stop()
self.lc = None