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

Python task.deferLater函数代码示例

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

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



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

示例1: atomize

    def atomize(self, ticket, xmlFile, atomize, userConf = None):
        reaction = 'config/reactionDefinitions.json'
        try:
            logStream = StringIO.StringIO()
            if userConf:
                jsonpointer = tempfile.mkstemp(suffix='.json', text=True)
                with open(jsonpointer[1], 'w') as f:
                    f.write(userConf)
                jsonpointer = jsonpointer[1]
            else:
                jsonpointer = None
            result = libsbml2bngl.readFromString(xmlFile,
                                                 reaction, False, jsonpointer, atomize, logStream)

            if result and atomize:
                pointer = tempfile.mkstemp(suffix='.bngl', text=True)
                with open(pointer[1], 'w') as f:
                    f.write(result.finalString)
                print pointer[1]
                bnglresult = libsbml2bngl.postAnalyzeString(pointer[1], bngDistro, result.database)
            else:
                bnglresult = result.finalString
            self.addToDict(ticket, [bnglresult, logStream.getvalue(), {'finalspecies':result.database.species, 'rawreactions':result.database.rawreactions}])
            print 'success', ticket

        except:
            self.addToDict(ticket, -5)
            print 'failure', ticket
        finally:
            task.deferLater(reactor, 600,  freeQueue, ticket)
开发者ID:RuleWorld,项目名称:atomizer,代码行数:30,代码来源:twistedServer.py


示例2: test_auto_retune

 def test_auto_retune(self):
     # pylint: disable=no-member
     
     f1 = 50e6  # avoid 100e6 because that's a default a couple of places
     dev = simulate.SimulatedDevice(freq=f1, allow_tuning=True)
     bandwidth = dev.get_rx_driver().get_output_type().get_sample_rate()
     top = Top(devices={'s1': dev})
     (_key, receiver) = top.add_receiver('AM', key='a')
     
     # initial state check
     receiver.set_rec_freq(f1)
     self.assertEqual(dev.get_freq(), f1)
     
     # one "page" up
     f2 = f1 + bandwidth * 3/4
     receiver.set_rec_freq(f2)
     self.assertEqual(dev.get_freq(), f1 + bandwidth)
     
     # must wait for tune_delay, which is 0 for simulated source, or it will look still-valid
     yield deferLater(the_reactor, 0.1, lambda: None)
     
     # one "page" down
     receiver.set_rec_freq(f1)
     self.assertEqual(dev.get_freq(), f1)
     
     yield deferLater(the_reactor, 0.1, lambda: None)
     
     # long hop
     receiver.set_rec_freq(200e6)
     self.assertEqual(dev.get_freq(), 200e6)
开发者ID:nunb,项目名称:shinysdr,代码行数:30,代码来源:test_top.py


示例3: privmsg

 def privmsg(self, user, target, msg):
     if not user or self.nickname not in msg:
         return
     sentence = self.factory.markov.generateString()
     deferLater(self.factory.reactor,
         len(sentence) / 500.0,
         self.msg, target, sentence)
开发者ID:moronbros,项目名称:saulbot,代码行数:7,代码来源:saulbot.py


示例4: __connect

 def __connect(self):
     print "lancement de la connection a redis",self.port," - ",self.unix
     retry = 10
     while not self.stopTrying:
         try: 
             if self.port:
                 self.redis = yield ClientCreator(reactor, Redis).connectTCP(__HOST__, self.port)
             elif self.unix:
                 self.redis = yield ClientCreator(reactor, Redis).connectUNIX(self.unix)
             else:
                 raise NotImplemented("PAS de port ou de socket fournit au client")
             r = yield self.redis.select(self.db)
             print r , self,self.port,self.unix
             self.ready.callback(True)
             
         except ConnectionRefusedError,e:
             print >>sys.stderr,"connection impossible",str(e)
             if not retry:
                 print "nombre d'essai fini on reessais dans 1 heure"
                 retry = 11
                 yield task.deferLater(reactor, 3600,lambda: None)
             retry -= 1
             print "on essais dans %i secondes"%(10 - retry)
             yield task.deferLater(reactor, (10 - retry),lambda: None)
         except Exception,e:
             print >>sys.stderr,"connection impossible sur ",self.port," ", self.unix," ",str(e)
             print "connection impossible sur ",self.port," ", self.unix," ",str(e)
             raise e
开发者ID:dynamikdev,项目名称:txredisTools,代码行数:28,代码来源:redisClient.py


示例5: parseNewPage

def parseNewPage(f, external_id, remaining=None, parser=None):
    spoon = 1024*10
    if remaining is None:
        remaining = f.tell()
        # TODO! how do i know, that the received fileis more than 1024???
        parser=etree.HTMLParser(target=NewTarget())#encoding='cp1251'
        f.seek(0)
        rd = f.read(spoon)
        parser.feed(rd)
        remaining -= spoon
        d = deferLater(reactor, 0, parseNewPage, f, external_id, remaining, parser)
        return d
    else:
        if remaining < spoon:
            rd = f.read(remaining)
            parser.feed(rd)
            f.close()
            parser.close()
            return parser.target.prepareNewComponents(external_id)
        else:
            rd = f.read(spoon)
            parser.feed(rd)
            remaining -= spoon
            d = deferLater(reactor, 1, parseNewPage, f, external_id, remaining, parser)
            return d
开发者ID:mysoftpro,项目名称:pc,代码行数:25,代码来源:catalog.py


示例6: delay

    def delay(self, seconds, function, *args, **kwargs):
        """
         delay(seconds, function, *args, **kwargs):

         Delay execution of function(*args, **kwargs) for up to 120 seconds.

         Error messages are relayed to caller unless a specific keyword
         'errobj' is supplied pointing to another object to receiver errors.
        """
        # handle the special error-reporting object
        errobj = self.caller
        if "errobj" in kwargs:
            errobj = kwargs["errobj"]
            del kwargs["errobj"]
        # set up some callbacks for delayed execution
        def errback(f, errobj):
            if errobj:
                try: f = f.getErrorMessage()
                except: pass
                errobj.msg("EVLANG delay error: " + str(f))
        def runfunc(func, *args, **kwargs):
            threads.deferToThread(func, *args, **kwargs).addErrback(errback, errobj)
        # get things going
        if seconds <= 120:
            task.deferLater(reactor, seconds, runfunc, function, *args, **kwargs).addErrback(errback, errobj)
        else:
            raise EvlangError("delay() can only delay for a maximum of 120 seconds (got %ss)." % seconds )
        return True
开发者ID:OthersGames,项目名称:asylum-jam,代码行数:28,代码来源:evlang.py


示例7: test_replay

    def test_replay(self):
        config = self.getConfig(StompSpec.VERSION_1_0)

        client = async.Stomp(config)
        client = yield client.connect(host=VIRTUALHOST)
        client.subscribe(self.queue, self._eatFrame, {StompSpec.ACK_HEADER: 'client-individual'})
        client.send(self.queue, self.frame)
        while self.framesHandled != 1:
            yield task.deferLater(reactor, 0.01, lambda: None)
        client._protocol.loseConnection()
        try:
            yield client.disconnected
        except StompConnectionError:
            pass
        client = yield client.connect(host=VIRTUALHOST)
        client.send(self.queue, self.frame)
        while self.framesHandled != 2:
            yield task.deferLater(reactor, 0.01, lambda: None)

        try:
            yield client.disconnect(failure=RuntimeError('Hi'))
        except RuntimeError as e:
            self.assertEquals(str(e), 'Hi')

        client = yield client.connect(host=VIRTUALHOST)
        client.send(self.queue, self.frame)
        while self.framesHandled != 2:
            yield task.deferLater(reactor, 0.01, lambda: None)

        yield client.disconnect()
开发者ID:irdetoakinavci,项目名称:AMQMessageProducer,代码行数:30,代码来源:async_client_integration_test.py


示例8: setup_crawler

def setup_crawler(
        spider_class,
        **kwargs
    ):
    """
    Use scrapy in a script
    see http://doc.scrapy.org/en/latest/topics/practices.html

    :param spider_class: Spider class to test
    :type spider_class: text
    """

    def add_item(item):
        items.append(item)

    items = []
    # create Crawler
    settings = get_project_settings()
    crawler = Crawler(settings)
    crawler.configure()
    # connect collecting function on item_passed
    crawler.signals.connect(add_item, signals.item_passed)
    # create & connect spider
    spider = spider_class(**kwargs)
    crawler.crawl(spider)
    # start crawler
    log.start()
    crawler.start()
    # run crawler
    task.deferLater(reactor, 1, reactor.stop)
    reactor.run()
    return items
开发者ID:deboute,项目名称:scrapy-howto,代码行数:32,代码来源:test_spiders.py


示例9: __checkPred

 def __checkPred(res):
     if res:
         target.callback(self)
         return res
     else:
         task.deferLater(reactor, poll, self.__wait, pred, poll, target)
         return
开发者ID:BillTheBest,项目名称:vmw.vco,代码行数:7,代码来源:client.py


示例10: test_retry_after_timeout

    def test_retry_after_timeout(self):
        """
        If a timeout happens, one can retry to consume message from the queue
        later on.
        """
        yield self.manager.connected((self.client, self.channel))
        yield self.channel.queue_declare(
            queue=self.queue_prefix + "uuid1")

        reply = yield self.client.queue(self.tag_prefix + "uuid1.0")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d1 = self.manager.get_message("uuid1", "0")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d1, Timeout)

        # Let's wrap the queue again
        reply = yield self.client.queue(self.tag_prefix + "uuid1.1")
        reply.clock = self.clock
        event_queue = QueueWrapper(reply).event_queue

        d2 = self.manager.get_message("uuid1", "1")
        yield event_queue.get()
        yield deferLater(reactor, 0, lambda: None)
        self.clock.advance(self.manager.message_timeout + 1)
        yield assert_fails_with(d2, Timeout)
开发者ID:CanonicalLtd,项目名称:txlongpoll,代码行数:29,代码来源:test_integration.py


示例11: testManySubscribers

    def testManySubscribers(self):
        """Subscribe 3 clients, expects 9 reqeusts 3x subscribe, 3x disconnect, 3x logged_out
        Check that service records correct data at each step"""
        self.webServer.expectRequests(9)
        
        client1 = MockFlashClient(1)
        client2 = MockFlashClient(2)
        client3 = MockFlashClient(3)
        client1.connectedEvent.addCallback(lambda _: client1.sendSubscribeMessage([1]))
        client2.connectedEvent.addCallback(lambda _: client2.sendSubscribeMessage([1]))
        client3.connectedEvent.addCallback(lambda _: client3.sendSubscribeMessage([2]))
        
        def assertsOnService(*a):
            self.assertEqual(len(self.service.channels.keys()), 2)
            self.assertEqual(len(self.service.channels[1]), 2)
            self.assertEqual(len(self.service.channels[2]), 1)
            self.assertEqual(len(self.service.clients.keys()), 3)
            self.assertEqual(self.service.clients.keys(), [1, 2, 3])
        task.deferLater(reactor, 0.05, assertsOnService
            ).addCallback(lambda _: client1.connector.disconnect()
            ).addCallback(lambda _: client2.connector.disconnect()
            ).addCallback(lambda _: client3.connector.disconnect())

        def assertClientsDead(*a):
            for channel in self.service.channels.values():
                for client in channel:
                    self.assertFalse(client.is_alive)
        self.webServer.getNFirstRequests(6).addCallback(assertsOnService #clients are not removed from channels yet, only marked as dead
            ).addCallback(assertClientsDead)
            
        def assertClientsRemoved(*a):
            self.assertEqual(len(self.service.channels.keys()), 0)
            self.assertEqual(len(self.service.clients.keys()), 0)
        self.webServer.getAllRequests().addCallback(assertClientsRemoved)
        return defer.DeferredList([client1.disconnectedEvent, client2.disconnectedEvent, client3.disconnectedEvent])
开发者ID:kowalski,项目名称:Twisted-juggernaut,代码行数:35,代码来源:subscribe_test.py


示例12: onStart

    def onStart(self):
        self.graphs = {}

        self._persistPath = PERSIST_PATH
        self.loadAll()

        deferLater(reactor, PERSIST_INTERVAL, self.periodicPersist)
开发者ID:petrushev,项目名称:graphx,代码行数:7,代码来源:app.py


示例13: region_instance

def region_instance(region_instance_seq):
    region, instance_id = region_instance_seq[0], region_instance_seq[1]
    print 'region:', region, 'instance:', instance_id
    if region == app_util.app_region:
        print 'connect to:', region
        for image in all_images(region):
            try:
                print 'de-register images:', image
                image.deregister()
                print 'wait 20 seconds'
                yield task.deferLater(reactor, 20, defer.succeed, True)        
            except Exception as e:
                print 'de-register error:', e
        print 'create image:', app_util.app_name
        r_conn = boto.ec2.connect_to_region(region)
        try:
            #for service_name in identify.service_names(region):
            #    os.system('sudo rm ' + identify.service_path(service_name) )
            for instance in r_conn.get_only_instances(instance_ids=[instance_id]):
                print 'instance to tag:', instance
                instance.add_tag(fixed.tag_state, fixed.state_replicate)
            ami_response = r_conn.create_image(instance_id, app_util.app_name)
            print 'ami response:', ami_response
        except Exception as e:
            print 'exception:', e       
    else:
        print 'region mismatch'
    yield task.deferLater(reactor, 1, defer.succeed, True)    
    print 'complete'
    reactor.callLater(0, reactor.stop)        
开发者ID:kmcintyre,项目名称:Snapyelp,代码行数:30,代码来源:ami.py


示例14: expose

def expose(application):
    def attachDnsController(dns_controller):
        #########
        # Mammatus is the giver of names, on TCP and UDP.
        ##
        verbosity = 0
        tcpFactory = names_server.DNSServerFactory(clients=[dns_controller], verbose=verbosity)
        udpFactory = names_dns.DNSDatagramProtocol(tcpFactory)
        tcpFactory.noisy = udpFactory.noisy = verbosity
        dns_service = service.MultiService()
        internet.TCPServer(53, tcpFactory).setServiceParent(dns_service)
        internet.UDPServer(53, udpFactory).setServiceParent(dns_service)
        dns_service.setServiceParent(application)
    def attachHttpController(http_controller):
        #########
        # Mammatus feeds you, over HTTP.
        ##
        httpFactory = web_server.Site(http_controller)
        web_service = internet.TCPServer(80, httpFactory)
        web_service.setServiceParent(application)

    #########
    # Expose Mammia
    ##
    deferDnsController = deferLater(reactor, 0, dns.getController, model)
    deferDnsController.addCallback(attachDnsController)
    deferHttpController = deferLater(reactor, 0, http.getController, model)
    deferHttpController.addCallback(attachHttpController)
开发者ID:thimbl,项目名称:Mammatus,代码行数:28,代码来源:mammia.py


示例15: test_transaction_commit

    def test_transaction_commit(self):
        config = self.getConfig(StompSpec.VERSION_1_0)
        client = async.Stomp(config)
        client.add(ReceiptListener())
        yield client.connect(host=VIRTUALHOST)
        client.subscribe(
            self.queue,
            {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL, StompSpec.ID_HEADER: "4711"},
            listener=SubscriptionListener(self._eatFrame, ack=True),
        )

        transaction = "4711"
        yield client.begin(transaction, receipt="%s-begin" % transaction)
        client.send(self.queue, b"test message with transaction", {StompSpec.TRANSACTION_HEADER: transaction})
        yield task.deferLater(reactor, 0.1, lambda: None)
        client.send(self.queue, b"test message without transaction")
        while self.framesHandled != 1:
            yield task.deferLater(reactor, 0.01, lambda: None)
        self.assertEquals(self.consumedFrame.body, b"test message without transaction")
        yield client.commit(transaction, receipt="%s-commit" % transaction)
        while self.framesHandled != 2:
            yield task.deferLater(reactor, 0.01, lambda: None)
        self.assertEquals(self.consumedFrame.body, b"test message with transaction")
        client.disconnect()
        yield client.disconnected
开发者ID:nikipore,项目名称:stompest,代码行数:25,代码来源:async_client_integration_test.py


示例16: onResponse

    def onResponse(self, responseContent, url):
        """Called when new content arrives"""

        links = extractLinks(responseContent, url)
        new_ = set(links.keys()).difference(self.history)
        self.history.update(new_)

        # send system notifications for new urls
        today = date.today()
        appendLog = ''

        messages = []

        for url in new_:
            title = links[url]
            title_enc = title.encode('utf-8', 'replace')
            msg = '{0} {1} : {2}\n'.format(today.strftime('%Y-%m-%d'), title_enc, url)
            appendLog = appendLog + msg

            if filterTitle(title, self.keywords) or filterUrl(url, self.domains):
                messages.append(MESSAGE_TPL.format(title, url, url))

        notify(messages)

        # update archive
        archiveName = today.strftime('archive-%Y-%m.txt')
        with open(archiveName, 'a') as f:
            f.write(appendLog)

        # schedule next crawl
        deferLater(reactor, self.interval, self.fetch)
开发者ID:petrushev,项目名称:hackerfeed,代码行数:31,代码来源:__init__.py


示例17: test_no_self_connect

def test_no_self_connect():
    """
    Test that when a producer connects, the consumer sends all existing
    subscription to it.

    """
    class WampConsumerServerFactory(ConsumerMixin, wamp.WampServerFactory):
        protocol = wamp.WampServerProtocol

    id = generate_id()
    consumer = ConsumerServer('localhost', 19200, id=id)
    consumer.processor = WampConsumerServerFactory('ws://localhost:19202')
    listenWS(consumer.processor)
    producer = ProducerClient(id=id)
    deferLater(reactor, 0.5, producer.connect, 'localhost', 19200)

    def check_connection():
        """
        Make sure producer has no connections, because it's been controlled.

        """
        print(set(producer.nodes))
        assert set(producer.nodes) == set()

    return deferLater(reactor, 1.0, check_connection)
开发者ID:luhn,项目名称:pubsubclub,代码行数:25,代码来源:__main__.py


示例18: deferred_route_twilio_call

def deferred_route_twilio_call(session_id, url, defer_time):
    '''
    Currently unused but potentially useful.
    '''
    twilio_rest_client = TwilioRestClient(API_tokens.TWILIO_SID, API_tokens.TWILIO_AUTH_TOKEN)
    deferLater(reactor, defer_time, twilio_rest_client.calls.route, session_id, url)
    return True
开发者ID:SlashRoot,项目名称:WHAT,代码行数:7,代码来源:response.py


示例19: _do_pull

    def _do_pull(
            self, i, num_pulls, hostname, subscr_info):
        prefix = "{0} {1}".format(hostname, subscr_info)
        subscription = self._subscriptions_dct[(hostname, subscr_info)]
        if num_pulls > 0 and i == num_pulls:
            yield subscription.unsubscribe()
            del self._subscriptions_dct[(hostname, subscr_info)]
            if not self._subscriptions_dct:
                self._d.callback(None)
            return
        i += 1
        sys.stdout.write('{0} pull #{1}'.format(prefix, i))
        if num_pulls > 0:
            sys.stdout.write(' of {0}'.format(num_pulls))
        print

        def print_event(event):
            self._event_count += 1
            print "{0} {1}".format(prefix, event)

        log.debug("subscription.pull- {0} {1} (start)"
                  .format(hostname, subscr_info))
        yield subscription.pull(print_event)
        log.debug("subscription.pull- {0} {1} (finished)"
                  .format(hostname, subscr_info))
        task.deferLater(reactor, 0, self._do_pull, i, num_pulls, hostname,
                        subscr_info)
开发者ID:Hexadite-Omri,项目名称:txwinrm,代码行数:27,代码来源:wecutil.py


示例20: startInventory

    def startInventory(self, *args):
        """Add a ROSpec to the reader and enable it."""
        if self.state == LLRPClient.STATE_INVENTORYING:
            logger.warn('ignoring startInventory() while already inventorying')
            return None

        logger.info('starting inventory')

        if self.duration:
            task.deferLater(reactor, self.duration, self.stopPolitely, True)

        rospec = self.getROSpec()['ROSpec']

        d2 = defer.Deferred()
        d2.addCallback(self.send_ENABLE_EVENTS_AND_REPORTS, onCompletion=None)
        d2.addErrback(self.panic, 'START_ROSPEC failed')

        d1 = defer.Deferred()
        d1.addCallback(self.send_START_ROSPEC, rospec, onCompletion=d2)
        d1.addErrback(self.panic, 'ENABLE_ROSPEC failed')

        d = defer.Deferred()
        d.addCallback(self.send_ENABLE_ROSPEC, rospec, onCompletion=d1)
        d.addErrback(self.panic, 'ADD_ROSPEC failed')

        self.send_ADD_ROSPEC(rospec, onCompletion=d)
开发者ID:troelsy,项目名称:sllurp,代码行数:26,代码来源:llrp.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python task.react函数代码示例发布时间:2022-05-27
下一篇:
Python task.coiterate函数代码示例发布时间: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