• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python task.LoopingCall类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.internet.task.LoopingCall的典型用法代码示例。如果您正苦于以下问题:Python LoopingCall类的具体用法?Python LoopingCall怎么用?Python LoopingCall使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: add

 def add(self, request, save_time = 0):
     self.data[request] = time.time() + save_time * 60
     d = request.notifyFinish()
     d.addCallback(self.notifyFinished, request)
     d.addErrback(self.notifyFinished, request)
     call = LoopingCall(self.prune)
     call.start(60)
开发者ID:Gnaget,项目名称:bitHopper,代码行数:7,代码来源:request_store.py


示例2: __init__

    def __init__(
        self, reactor, request, request_rate=10,
        sample_size=DEFAULT_SAMPLE_SIZE, timeout=45,
        tolerance_percentage=0.2
    ):
        """
        ``RequestLoadScenario`` constructor.

        :param tolerance_percentage: error percentage in the rate that is
            considered valid. For example, if we request a ``request_rate``
            of 20, and we give a tolerance_percentage of 0.2 (20%), anything
            in [16,20] will be a valid rate.
        """
        self.reactor = reactor
        self.request = request
        self.request_rate = request_rate
        self.timeout = timeout
        self._maintained = Deferred()
        self.rate_measurer = RateMeasurer(sample_size)
        self.max_outstanding = 10 * request_rate
        self.tolerated_errors = 5 * request_rate
        # Send requests per second
        self.loop = LoopingCall.withCount(self._request_and_measure)
        self.loop.clock = self.reactor
        # Monitor the status of the scenario
        self.monitor_loop = LoopingCall(self.check_rate)
        self.monitor_loop.clock = self.reactor
        self.is_started = False
        self.rate_tolerated = (
            float(request_rate) - (request_rate*tolerance_percentage)
        )
开发者ID:ClusterHQ,项目名称:flocker,代码行数:31,代码来源:_request_load.py


示例3: PollingDataStream

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)
开发者ID:ralphbean,项目名称:moksha,代码行数:34,代码来源:datastream.py


示例4: __init__

class BandwidthEstimator:
    bufsize = 20
    totalBytes = 0
    def __init__(self, message, length):
        self.length = length
        self.message = message
        self.estim = []
        self.bytes = 0
        self.call = LoopingCall(self.estimateBandwidth)
        self.call.start(1)

    def estimateBandwidth(self):
        bytes = self.bytes
        self.totalBytes += bytes
        self.estim.append(bytes)
        self.message("%0.2f k/s (%0.2d%%)"
                     % ((sum(self.estim) / len(self.estim)) / 1024.,
                        (float(self.totalBytes) / self.length) * 100))
        if len(self.estim) > self.bufsize:
            self.estim.pop(0)
        self.bytes = 0

    def stop(self):
        self.call.stop()
        self.estimateBandwidth()
        self.message("Finished receiving: %d bytes (%d%%)" % (
                self.totalBytes, (float(self.totalBytes) / self.length) * 100))
开发者ID:rcarmo,项目名称:divmod.org,代码行数:27,代码来源:q2qclient.py


示例5: Pinger

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()
开发者ID:Elenw,项目名称:flocker,代码行数:28,代码来源:_protocol.py


示例6: __init__

 def __init__(self):
     self.output("TWS init")
     self.username = environ["TXTRADER_USERNAME"]
     self.password = environ["TXTRADER_PASSWORD"]
     self.xmlrpc_port = int(environ["TXTRADER_XMLRPC_PORT"])
     self.tcp_port = int(environ["TXTRADER_TCP_PORT"])
     self.callback_timeout = int(environ["TXTRADER_TWS_CALLBACK_TIMEOUT"])
     if not self.callback_timeout:
         self.callback_timeout = DEFAULT_TWS_CALLBACK_TIMEOUT
     self.output("callback_timeout=%d" % self.callback_timeout)
     self.enable_ticker = bool(int(environ["TXTRADER_ENABLE_TICKER"]))
     self.label = "TWS Gateway"
     self.channel = "tws"
     self.current_account = ""
     self.clients = set([])
     self.orders = {}
     self.pending_orders = {}
     self.openorder_callbacks = []
     self.accounts = []
     self.account_data = {}
     self.positions = {}
     self.position_callbacks = []
     self.executions = {}
     self.execution_callbacks = []
     self.bardata_callbacks = []
     self.cancel_callbacks = []
     self.order_callbacks = []
     self.addsymbol_callbacks = []
     self.accountdata_callbacks = []
     self.last_connection_status = ""
     self.connection_status = "Initializing"
     self.LastError = -1
     self.next_order_id = -1
     self.last_minute = -1
     self.handlers = {
         "error": self.error_handler,
         "tickSize": self.handle_tick_size,
         "tickPrice": self.handle_tick_price,
         "tickString": self.handle_tick_string,
         "nextValidId": self.handle_next_valid_id,
         "currentTime": self.handle_time,
         "managedAccounts": self.handle_accounts,
         "orderStatus": self.handle_order_status,
         "openOrder": self.handle_open_order,
         "openOrderEnd": self.handle_open_order_end,
         "execDetails": self.handle_exec_details,
         "execDetailsEnd": self.handle_exec_details_end,
         "position": self.handle_position,
         "positionEnd": self.handle_position_end,
         "historicalData": self.handle_historical_data,
         "updateAccountValue": self.handle_account_value,
         "accountDownloadEnd": self.handle_account_download_end,
     }
     self.ticker_ids = {}
     self.symbols = {}
     self.symbols_by_id = {}
     self.primary_exchange_map = {}
     self.tws_conn = None
     repeater = LoopingCall(self.EverySecond)
     repeater.start(1)
开发者ID:distagon,项目名称:txTrader,代码行数:60,代码来源:tws.py


示例7: __init__

    def __init__(self, settings, strategy_class):
        partition_id = settings.get('SCORING_PARTITION_ID')
        if partition_id is None or type(partition_id) != int:
            raise AttributeError("Scoring worker partition id isn't set.")

        messagebus = load_object(settings.get('MESSAGE_BUS'))
        mb = messagebus(settings)
        spider_log = mb.spider_log()
        scoring_log = mb.scoring_log()
        self.consumer = spider_log.consumer(partition_id=partition_id, type=b'sw')
        self.scoring_log_producer = scoring_log.producer()

        self._manager = FrontierManager.from_settings(settings, strategy_worker=True)
        codec_path = settings.get('MESSAGE_BUS_CODEC')
        encoder_cls = load_object(codec_path+".Encoder")
        decoder_cls = load_object(codec_path+".Decoder")
        self._decoder = decoder_cls(self._manager.request_model, self._manager.response_model)
        self._encoder = encoder_cls(self._manager.request_model)

        self.update_score = UpdateScoreStream(self._encoder, self.scoring_log_producer, 1024)
        self.states_context = StatesContext(self._manager.backend.states)

        self.consumer_batch_size = settings.get('SPIDER_LOG_CONSUMER_BATCH_SIZE')
        self.strategy = strategy_class.from_worker(self._manager, self.update_score, self.states_context)
        self.states = self._manager.backend.states
        self.stats = {
            'consumed_since_start': 0
        }
        self.job_id = 0
        self.task = LoopingCall(self.work)
        self._logging_task = LoopingCall(self.log_status)
        self._flush_states_task = LoopingCall(self.flush_states)
        logger.info("Strategy worker is initialized and consuming partition %d", partition_id)
开发者ID:Preetwinder,项目名称:frontera,代码行数:33,代码来源:strategy.py


示例8: reconfigServiceWithBuildbotConfig

    def reconfigServiceWithBuildbotConfig(self, new_config):
        # first, enable or disable
        if new_config.metrics is None:
            self.disable()
        else:
            self.enable()

            metrics_config = new_config.metrics

            # Start up periodic logging
            log_interval = metrics_config.get('log_interval', 60)
            if log_interval != self.log_interval:
                if self.log_task:
                    self.log_task.stop()
                    self.log_task = None
                if log_interval:
                    self.log_task = LoopingCall(self.report)
                    self.log_task.clock = self._reactor
                    self.log_task.start(log_interval)

            # same for the periodic task
            periodic_interval = metrics_config.get('periodic_interval', 10)
            if periodic_interval != self.periodic_interval:
                if self.periodic_task:
                    self.periodic_task.stop()
                    self.periodic_task = None
                if periodic_interval:
                    self.periodic_task = LoopingCall(periodicCheck,
                                                     self._reactor)
                    self.periodic_task.clock = self._reactor
                    self.periodic_task.start(periodic_interval)

        # upcall
        return util_service.ReconfigurableServiceMixin.reconfigServiceWithBuildbotConfig(self,
                                                                                         new_config)
开发者ID:kenygia,项目名称:buildbot,代码行数:35,代码来源:metrics.py


示例9: WebSocketConnection

class WebSocketConnection(WebSocketProtocol):
	def __init__(self, stateObject):
		self.state = stateObject
		self.opcode = TEXT
		WebSocketProtocol.__init__(self, WebSocketReceiver(self))
		self.finished = Deferred()
		self.pingLoop = LoopingCall(self.doPing)

	def doPing(self):
		self.receiver.transport.sendFrame(PING, '')

	def write(self, data):
		self.receiver.transport.sendFrame(self.opcode, data)

	def sendFrame(self, opcode, data):
		self.receiver.transport.sendFrame(opcode, data)

	def writeSequence(self, data):
		for chunk in data:
			self.write(chunk)

	def connectionLost(self, reason):
		if self.pingLoop.running:
			self.pingLoop.stop()
		self.finished.callback(self)
开发者ID:intangere,项目名称:Essence,代码行数:25,代码来源:server.py


示例10: __init__

    def __init__(self):
        """
        Initialize the model. This doesn't add any documents yet.
        """
        silenceGensim()

        self.dictionaries = dict()
        self.preprocessor = TokenizingPorter2Stemmer()

        #this dict keeps a model for every source type
        #  (since e.g. RSS feeds should be treated separately from twitter feeds)
        self.models = dict()

        #this dict keeps a dictionary for every source type 
        self.dictionaries = dict()

        self.queue = Queue()
        self.modelQueue = Queue()
        self.nodeCommunicator = NodeCommunicator(self, LISTEN_PORT)
        self.nodeCommunicator.registerWithNode(CORE_IP, REGISTER_PORT)  # register this node with the core

        ln.info("LSA Initialized")
        self.updating = False
        loop = LoopingCall(self.update)
        loop.start(5)

        reactor.run()
开发者ID:amsqr,项目名称:holist,代码行数:27,代码来源:LSAStrategy.py


示例11: CacheService

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()
开发者ID:bramwelt,项目名称:ganeti_webmgr,代码行数:27,代码来源:service.py


示例12: onJoin

    def onJoin(self, details):
        log.msg("PiMonitor connected")

        extra = self.config.extra

        self._id = extra['id']
        self.publish_temperature = True
        self.threshold = 0

        self._tick = 0
        self._cpu_temp_celsius = None

        def scanTemperature():
            self._cpu_temp_celsius = float(open("/sys/class/thermal/thermal_zone0/temp").read()) / 1000.
            
            if self.publish_temperature:
                self.publish(u'io.crossbar.examples.pi.{}.tempmon.on_temperature'.format(self._id), self._tick, self._cpu_temp_celsius)
                self._tick += 1

            if self.threshold > 0 and self._cpu_temp_celsius > self.threshold:
                self.publish(u'io.crossbar.examples.pi.{}.tempmon.on_threshold_exceeded'.format(self._id), self._tick, self._cpu_temp_celsius)
          
        scan = LoopingCall(scanTemperature)
        scan.start(1)

        for proc in [self.get_temperature, self.impose_stress, self.toggle_publish, self.set_threshold]:
            uri = u'io.crossbar.examples.pi.{}.tempmon.{}'.format(self._id, proc.__name__)
            yield self.register(proc, uri)
            log.msg("Registered {}".format(uri))

        log.msg("PiMonitor ready.")
开发者ID:AntonioJR0,项目名称:crossbarexamples,代码行数:31,代码来源:tempmon_pi.py


示例13: __init__

class Hoster:
	def __init__(self, screen, port):
		self.screen = screen
		self.port = port

	def start(self):
		# Set up the connection between the state and the network;
		# using queues gives a degree of seperation between the
		# communication and game logic, and making them be deferred
		# keeps it all asynchronous.
		inqueue = DeferredQueue()
		outqueue = DeferredQueue()

		#Initialize GameState
		gs = GameState(self,self.screen,1,inqueue,outqueue)

		#Create Looping Call
		self.lc = LoopingCall(gs.gameLoop)
		self.lc.start(.0166666666)
		
		#Begin Listening
		connfactory = CommandConnFactory(inqueue,outqueue)
		self.listening = reactor.listenTCP(self.port,connfactory)

	def stop(self, nextscreen=None):
		# Stop the GameState logic, and let go of the port on which we're listening
		self.lc.stop()
		self.listening.stopListening()

		# Start up the next screen, if there is one
		if nextscreen:
			nextscreen.start()
		else: reactor.stop()
开发者ID:mbau,项目名称:memory,代码行数:33,代码来源:home.py


示例14: delayed_setup

    def delayed_setup(self):
        self.feeds = []

        self.failures.clear()
        self.feed_times.clear()
        self.targets.clear()
        self.tasks.clear()

        for name, target in self.config["targets"].items():
            proto = target["protocol"]
            if proto in self.factory_manager.factories:
                self.targets[name] = target
            else:
                self.logger.warn("Unknown protocol '%s' in target '%s'"
                                 % (proto, name))

        for feed in self.config["feeds"]:
            append = True
            for target in feed["targets"]:
                if target["name"] not in self.targets:
                    self.logger.warn("Unknown target '%s' for feed '%s'"
                                     % (target["name"], feed["name"]))
                    append = False
                    break

            if append:
                self.feeds.append(feed)

        for feed in self.feeds:
            task = LoopingCall(self.check_feed, feed)
            self.tasks[feed["name"]] = task
            task.start(feed["frequency"])
开发者ID:EionRobb,项目名称:Ultros-contrib,代码行数:32,代码来源:__init__.py


示例15: make_lc

def make_lc(self, reactor, func):

    if DEBUG:
        self.stdout_length = 0
        self.stderr_length = 0

    def _(lc, reactor):
        if DEBUG:
            stdout = self.stdout.getvalue()
            stderr = self.stderr.getvalue()

            if self.stdout.getvalue()[self.stdout_length:]:
                print(self.stdout.getvalue()[self.stdout_length:],
                      file=sys.__stdout__)
            if self.stderr.getvalue()[self.stderr_length:]:
                print(self.stderr.getvalue()[self.stderr_length:],
                      file=sys.__stderr__)

            self.stdout_length = len(stdout)
            self.stderr_length = len(stderr)

        return func(lc, reactor)

    lc = LoopingCall(_)
    lc.a = (lc, reactor)
    lc.clock = reactor
    lc.start(0.1)
    return lc
开发者ID:snowattitudes,项目名称:crossbar,代码行数:28,代码来源:test_run.py


示例16: EventGenerator

class EventGenerator(Node):
    """ (TEST) A timer-based event generator """

    # --- Initialization
    def __init__(self):
        self.count = 0

    # --- Interfaces
    def configure(self):

        self.events = (
            'event1',
            'event2',
        )

    def setup(self):
        self.status.set_GREEN()

        self.loop1 = LoopingCall(self.loop_cb1)
        self.loop1.start(3, False)

        self.loop2 = LoopingCall(self.loop_cb2)
        self.loop2.start(4, False)

    # --- Workers
    def loop_cb1(self):
        self.count += 1
        self.sendEvent('event1', self.count)

    def loop_cb2(self):
        self.count += 1
        self.sendEvent('event2', self.count)
开发者ID:sveinse,项目名称:lumina,代码行数:32,代码来源:event_generator.py


示例17: ServerController

class ServerController(object):
    def __init__(self, realm, view):
        print('server cont!')
        self.realm = realm
        self.view = view
        
    def _handleInput(self):
        """
        Handle currently available pygame input events.
        """
        for event in pygame.event.get():
            if (event.type == pygame.QUIT) or ((event.type == pygame.KEYDOWN) and (event.key == QUIT)):
                reactor.stop()
                sys.exit()
                
            if (event.type == pygame.KEYDOWN):
                if (event.key == START_GAME):
                    self.realm.environment.startGame()
                elif (event.key == RESET_GAME):
                    self.realm.environment.setPreGame()
    
    def go(self):
        self.previousTime = pygame.time.get_ticks()
        self._inputCall = LoopingCall(self._handleInput)
        d = self._inputCall.start(0.03)
        return d


    def stop(self):
        self._inputCall.stop()
开发者ID:FashGek,项目名称:flatland-arg,代码行数:30,代码来源:ServerKeyboardController.py


示例18: startService

	def startService(self):
		self.log.info("Starting up...")
		self.startupTime = now()
		self.log.info("Loading configuration...")
		self.config.reload()
		self.name = self.config["server_name"]
		self.serverID = self.config["server_id"]
		self.log.info("Loading storage...")
		self.storage = shelve.open(self.config["datastore_path"], writeback=True)
		self.storageSyncer = LoopingCall(self.storage.sync)
		self.storageSyncer.start(self.config.get("storage_sync_interval", 5), now=False)
		self.log.info("Starting processes...")
		self.pruneRecentlyQuit = LoopingCall(self.pruneQuit)
		self.pruneRecentlyQuit.start(10, now=False)
		self.pruneRecentChannels = LoopingCall(self.pruneChannels)
		self.pruneRecentChannels.start(15, now=False)
		self.log.info("Loading modules...")
		self._loadModules()
		self.log.info("Binding ports...")
		self._bindPorts()
		self.log.info("txircd started!")
		try:
			self._logFilter.setLogLevelForNamespace("txircd", LogLevel.levelWithName(self.config["log_level"]))
		except (KeyError, InvalidLogLevelError):
			self._logFilter.setLogLevelForNamespace("txircd", LogLevel.warn)
		self.runActionStandard("startup")
开发者ID:ElementalAlchemist,项目名称:txircd,代码行数:26,代码来源:ircd.py


示例19: _ExchangeRate

class _ExchangeRate(object):
    """Download an exchange rate from Yahoo Finance using Twisted."""

    def __init__(self, name):
        self._value = None
        self._name = name

    # External API:
    def latest_value(self):
        """Return the latest exchange rate value.

        May be None if no value is available.
        """
        return self._value

    def start(self):
        """Start the background process."""
        self._lc = LoopingCall(self._download)
        # Run immediately, and then every 30 seconds:
        self._lc.start(30, now=True)

    def _download(self):
        """Download the page."""
        print("Downloading!")
        def parse(result):
            print("Got %r back from Yahoo." % (result,))
            values = result.strip().split(",")
            self._value = float(values[1])
        d = getPage(
            "http://download.finance.yahoo.com/d/quotes.csv?e=.csv&f=c4l1&s=%s=X"
            % (self._name,))
        d.addCallback(parse)
        d.addErrback(log.err)
        return d
开发者ID:bencord0,项目名称:crochet,代码行数:34,代码来源:scheduling.py


示例20: wait_for_volume

    def wait_for_volume(self, name):
        """
        Wait for a volume by the given name, owned by thus service, to exist.

        Polls the storage pool for the specified volume to appear.

        :param VolumeName name: The name of the volume.

        :return: A ``Deferred`` that fires with a :class:`Volume`.
        """
        # Change this to not create the Volume instance right away.  Instead,
        # try to find it by uuid/name in `check_for_volume`.  If a Volume
        # instance there matches, use that object as the final result of the
        # Deferred returned by this method (it will have its other attributes
        # set correctly because they will be set correctly by enumerate).
        # FLOC-976
        volume = Volume(uuid=self.uuid, name=name, service=self)

        def check_for_volume(volumes):
            if volume in volumes:
                call.stop()

        def loop():
            d = self.enumerate()
            d.addCallback(check_for_volume)
            return d

        call = LoopingCall(loop)
        call.clock = self._reactor
        d = call.start(WAIT_FOR_VOLUME_INTERVAL)
        d.addCallback(lambda _: volume)
        return d
开发者ID:gnomix,项目名称:flocker,代码行数:32,代码来源:service.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python threads.blockingCallFromThread函数代码示例发布时间:2022-05-27
下一篇:
Python task.Clock类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap