How to use the twisted.internet.task.LoopingCall function in Twisted

To help you get started, we’ve selected a few Twisted examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aalex / toonloop / rats / render.py View on Github external
def _setup_events_looping_call(self):
        """
        Sets up the self._looping_events_check LoopingCall.
        """
        self._looping_events_check = task.LoopingCall(self.check_for_events)
        deferred = self._looping_events_check.start(0.01, True) # now=True
        # FIXME: events are check at 100 fps ! Make configurable.
        deferred.addErrback(self._on_events_error)
github privcount / privcount / src / tallyListener.py View on Github external
f1.write('No stats for this epoch\n')

    #start at the beginning of an epoch
    time.sleep(epoch - int(time.time())%epoch)
    print "TS starting up..."
    last_epoch_start = int(time.time())/epoch

    def epoch_change():
        global last_epoch_start
        now = int(time.time())/epoch
        if now > last_epoch_start:
            print "Epoch change!\n"
            last_epoch_start = now
            reactor.callLater(ts_pub_delay, publish_stats)

    epoch_check = task.LoopingCall(epoch_change)
    epoch_check.start(1)

    factory = protocol.ServerFactory()
    factory.protocol = tallyListener

    reactor.listenSSL(int(args.port), factory, ssl.DefaultOpenSSLContextFactory('keys/tally.key', 'keys/tally.cert'))
    print "TS started!"
    reactor.run()
github evennia / evennia / evennia / server / portal / imc2.py View on Github external
def start(self):
        "Connect session to sessionhandler"
        def errback(fail):
            logger.log_err(fail.value)

        if self.port:
            service = internet.TCPClient(self.network, int(self.port), self)
            self.sessionhandler.portal.services.addService(service)
        # start tasks
        self.task_isalive = task.LoopingCall(self.bot._isalive)
        self.task_keepalive = task.LoopingCall(self.bot._keepalive)
        self.task_prune = task.LoopingCall(self.bot._prune)
        self.task_channellist = task.LoopingCall(self.bot._channellist)
        self.task_isalive.start(900, now=False)
        self.task_keepalive.start(3500, now=False)
        self.task_prune.start(1800, now=False)
        self.task_channellist.start(3600 * 24, now=False)
github n0mjs710 / DMRlink / confbridge.py View on Github external
def config_reports(_config, _logger, _factory):
    if _config['REPORTS']['REPORT_NETWORKS'] == 'PRINT':
        def reporting_loop(_logger):
            _logger.debug('Periodic Reporting Loop Started (PRINT)')
            for system in _config['SYSTEMS']:
                print_master(_config, system)
                print_peer_list(_config, system)
        
        reporting = task.LoopingCall(reporting_loop, _logger)
        reporting.start(_config['REPORTS']['REPORT_INTERVAL'])
        report_server = False
                
    elif _config['REPORTS']['REPORT_NETWORKS'] == 'NETWORK':
        def reporting_loop(_logger, _server):
            _logger.debug('Periodic Reporting Loop Started (NETWORK)')
            _server.send_config()
            _server.send_bridge()
            
        _logger.info('DMRlink TCP reporting server starting')
        
        report_server = _factory(_config, _logger)
        report_server.clients = []
        reactor.listenTCP(_config['REPORTS']['REPORT_PORT'], report_server)
        
        reporting = task.LoopingCall(reporting_loop, _logger, report_server)
github Tribler / dispersy / discovery / community.py View on Github external
def __init__(self, filename, community, limit=100):
        assert isinstance(filename, (str, unicode)), type(filename)

        super(PeerCache, self).__init__()
        self._logger = logging.getLogger(self.__class__.__name__)

        self.filename = filename
        self.community = community
        self.walkcandidates = {}
        self.walkcandidates_limit = limit
        self.info_keys = ['last_seen', 'last_checked', 'num_fails']
        self.load()

        self.community.register_task("clean_and_save_peer_cache", LoopingCall(self.clean_and_save)).start(30, now=False)
github opacam / Cohen3 / coherence / backends / flickr_storage.py View on Github external
ignore_patterns = kwargs.get('ignore_patterns', [])
        ignore_file_pattern = re.compile(
            r'|'.join([r'^\..*'] + list(ignore_patterns))
        )

        self.wmc_mapping = {'16': 0}

        self.update_id = 0
        self.flickr = Proxy(b'http://api.flickr.com/services/xmlrpc/')
        self.flickr_api_key = '837718c8a622c699edab0ea55fcec224'
        self.flickr_api_secret = '30a684822c341c3c'
        self.store = {}
        self.uploads = {}

        self.refresh_store_loop = task.LoopingCall(self.refresh_store)
        self.refresh_store_loop.start(self.refresh, now=False)
        # self.server.coherence.store_plugin_config(
        #     self.server.uuid, {'test':'äöüß'})

        self.flickr_userid = kwargs.get('userid', None)
        self.flickr_password = kwargs.get('password', None)
        self.flickr_permissions = kwargs.get('permissions', 'read')

        self.flickr_authtoken = kwargs.get('authtoken', None)

        if (
            self.flickr_authtoken is None
            and self.server.coherence.writeable_config()
        ):
            if None not in (self.flickr_userid, self.flickr_password):
                d = self.flickr_authenticate_app()
github itamarst / crochet / examples / scheduling.py View on Github external
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)
github buildbot / buildbot / master / buildbot / changes / monotone.py View on Github external
def startService(self):
        self.loop = LoopingCall(self.start_poll)
        self.loop.start(self.pollinterval)
        service.Service.startService(self)
github OpenBazaar / OpenBazaar-Server / seed / httpseed.py View on Github external
def __init__(self, kserver_r):
                resource.Resource.__init__(self)
                self.kserver = kserver_r
                self.nodes = {}
                for bucket in self.kserver.protocol.router.buckets:
                    for node in bucket.getNodes():
                        self.nodes[(node.ip, node.port)] = node
                self.nodes[(this_node.ip, this_node.port)] = this_node
                loopingCall = task.LoopingCall(self.crawl)
                loopingCall.start(180, True)
github bravoserver / bravo / bravo / plugins / automatons.py View on Github external
def __init__(self, factory):
        self.factory = factory

        self.r = Random()
        self.tracked = deque()
        self.loop = LoopingCall(self.process)