当前位置: 首页>>代码示例>>Python>>正文


Python reactor.callLater函数代码示例

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


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

示例1: createDirectory

 def createDirectory(self, childName):
     d = defer.Deferred()
     d2 = defer.maybeDeferred(inmem.FakeDirectory.createDirectory,
                              self, childName)
     from twisted.internet import reactor
     reactor.callLater(1, d2.chainDeferred, d)
     return d
开发者ID:Almad,项目名称:twisted,代码行数:7,代码来源:test_sftp.py

示例2: launch

 def launch(howmany):        
     print 'launch' + str(howmany)            
     if howmany > 0:
         loop('test' + str(howmany), Gardener())
         reactor.callLater(1, lambda: launch(howmany - 1))
     elif howmany == 0:
         print 'done!'
开发者ID:kmcintyre,项目名称:gardenpath,代码行数:7,代码来源:alexa.py

示例3: testStopAndCancelWithOneUnderway

    def testStopAndCancelWithOneUnderway(self):
        """
        Start a dispatch queue of width 2, and send it 3 jobs. Verify that
        2 of the jobs are underway. Then stop it before they can complete,
        telling it to cancel the underway jobs. The two jobs that were
        underway should both be cancelled and returned by the stop method.
        The first 2 jobs returned should have state CANCELLED, and the
        final one should still be PENDING.
        """
        def ok(result):
            self.fail('Unexpected success!')

        def checkCancel(failure):
            self.assertEqual(failure.value.state, Job.CANCELLED)

        dq = ResizableDispatchQueue(self.slow, 2)
        dq.put(0).addCallbacks(ok, checkCancel)
        dq.put(1).addCallbacks(ok, checkCancel)
        dq.put(2)
        reactor.callLater(0.01, self._testUnderway, dq, set([0, 1]))
        pendingJobs = yield task.deferLater(
            reactor, 0.1, dq.stop, cancelUnderway=True)
        pendingArgs = [p.jobarg for p in pendingJobs]
        self.assertEqual([0, 1, 2], sorted(pendingArgs))
        self.assertEqual(pendingJobs[0].state, Job.CANCELLED)
        self.assertEqual(pendingJobs[1].state, Job.CANCELLED)
        self.assertEqual(pendingJobs[2].state, Job.PENDING)
开发者ID:jcollie,项目名称:txrdq,代码行数:27,代码来源:test_rdq.py

示例4: try_login

 def try_login(self, uname):
     if (self.cf.instance != None):
         self.cf.instance.login(uname)
         self.uname = uname
         return True
     
     reactor.callLater(0.25, self.try_login, uname)
开发者ID:skierkyles,项目名称:TISCaP_Client,代码行数:7,代码来源:main.py

示例5: start

 def start(self):       
    myJid = jid.JID(self.username)
    factory = client.XMPPClientFactory(myJid, self.password)
    factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)       
    connector = SRVConnector(reactor, 'xmpp-client', self.jabberserver, factory)       
    reactor.callLater(5, self.stop)
    connector.connect()    
开发者ID:cool-shark,项目名称:crashxmpp,代码行数:7,代码来源:crashxmpp.py

示例6: testKeyboardInterrupt

    def testKeyboardInterrupt(self):
        # Test the KeyboardInterrupt is *not* caught by wait -- we
        # want to allow users to Ctrl-C test runs.  And the use of the
        # useWaitError should not matter in this case.
        def raiseKeyInt(ignored):

            # XXX Abstraction violation, I suppose.  However: signals are
            # unreliable, so using them to simulate a KeyboardInterrupt
            # would be sketchy too; os.kill() is not available on Windows,
            # so we can't use that and let this run on Win32; raising
            # KeyboardInterrupt itself is wholely unrealistic, as the
            # reactor would normally block SIGINT for its own purposes and
            # not allow a KeyboardInterrupt to happen at all!

            if interfaces.IReactorThreads.providedBy(reactor):
                reactor.callInThread(reactor.sigInt)
            else:
                reactor.callLater(0, reactor.sigInt)
            return defer.Deferred()

        d = defer.Deferred()
        d.addCallback(raiseKeyInt)
        reactor.callLater(0, d.callback, True)
        self.assertRaises(KeyboardInterrupt, util.wait, d, useWaitError=False)

        d = defer.Deferred()
        d.addCallback(raiseKeyInt)
        reactor.callLater(0, d.callback, True)
        self.assertRaises(KeyboardInterrupt, util.wait, d, useWaitError=True)
开发者ID:pwarren,项目名称:AGDeviceControl,代码行数:29,代码来源:test_util.py

示例7: timeout_checker

 def timeout_checker(self):
     """
     Called periodically to enforce timeout rules on all connections.
     Also checks pings at the same time.
     """
     self.factory.check_timeouts()
     reactor.callLater(2, self.timeout_checker)
开发者ID:bibinjose22,项目名称:daphne,代码行数:7,代码来源:server.py

示例8: connected

    def connected(self, msg):
        """Once I've connected I want to subscribe to my the message queue.
        """
        stomper.Engine.connected(self, msg)

        self.log.info("senderID:%s Connected: session %s." % (
            self.senderID, 
            msg['headers']['session'])
        )

        # I originally called loopingCall(self.send) directly, however it turns
        # out that we had not fully subscribed. This meant we did not receive 
        # out our first send message. I fixed this by using reactor.callLater
        # 
        #
        def setup_looping_call():
            lc = LoopingCall(self.send)
            lc.start(2)
            
        reactor.callLater(1, setup_looping_call)

        f = stomper.Frame()
        f.unpack(stomper.subscribe(DESTINATION))

        # ActiveMQ specific headers:
        #
        # prevent the messages we send comming back to us.
        f.headers['activemq.noLocal'] = 'true'
        
        return f.pack()
开发者ID:NurKaynar,项目名称:hacklab,代码行数:30,代码来源:sender.py

示例9: __init__

 def __init__(self):
     self.clients = []
     self.game = Game()
     self.mob = Actor("eeeeeeewwwwwww")
     self.game.place(self.mob, (1,1))
     self.game.register(self.on_notify)
     reactor.callLater(1, self.tick)
开发者ID:elmore,项目名称:sixthdev,代码行数:7,代码来源:gamed.py

示例10: _work_done

 def _work_done(res):
     log.msg("Completed a piece of work")
     self.queue.pop(0)
     if self.queue:
         log.msg("Preparing next piece of work")
         reactor.callLater(0, self._process)
     return res
开发者ID:Callek,项目名称:buildbot,代码行数:7,代码来源:libvirtbuildslave.py

示例11: commandRestore

 def commandRestore(self, parts, fromloc, overriderank):
     "/restore worldname number - Op\nRestore world to indicated number."
     if len(parts) < 2:
         self.client.sendServerMessage("Please specify at least a world ID!")
     else:
         world_id = parts[1].lower()
         world_dir = ("worlds/%s/" % world_id)
         if len(parts) < 3:
             backups = os.listdir(world_dir + "backup/")
             backups.sort(lambda x, y: int(x) - int(y))
             backup_number = str(int(backups[-1]))
         else:
             backup_number = parts[2]
         if not os.path.exists(world_dir + "backup/%s/" % backup_number):
             self.client.sendServerMessage("Backup %s does not exist." % backup_number)
         else:
             if not os.path.exists(world_dir + "blocks.gz.new"):
                 shutil.copy((world_dir + "backup/%s/blocks.gz" % backup_number), world_dir)
                 if os.path.exists(world_dir + "backup/%s/world.meta" % backup_number):
                     shutil.copy((world_dir + "backup/%s/world.meta" % backup_number), world_dir)
             else:
                 reactor.callLater(1, self.commandRestore, self, parts, fromloc, overriderank)
             self.client.factory.unloadWorld(world_id, skiperror=True)
             self.client.sendServerMessage("%s has been restored to %s and booted." % (world_id, backup_number))
             if world_id in self.client.factory.worlds:
                 for client in self.client.factory.worlds[world_id].clients:
                     client.changeToWorld(world_id)
开发者ID:BPzeBanshee,项目名称:Arc,代码行数:27,代码来源:worldutil.py

示例12: _postTo

    def _postTo(self, callbacks, service, nodeIdentifier,
                      payload=None, contentType=None, eventType=None,
                      redirectURI=None):

        if not callbacks:
            return

        postdata = None
        nodeURI = getXMPPURI(service, nodeIdentifier)
        headers = {'Referer': nodeURI.encode('utf-8'),
                   'PubSub-Service': service.full().encode('utf-8')}

        if payload:
            postdata = payload.toXml().encode('utf-8')
            if contentType:
                headers['Content-Type'] = "%s;charset=utf-8" % contentType

        if eventType:
            headers['Event'] = eventType

        if redirectURI:
            headers['Link'] = '<%s>; rel=alternate' % (
                              redirectURI.encode('utf-8'),
                              )

        def postNotification(callbackURI):
            f = getPageWithFactory(str(callbackURI),
                                   method='POST',
                                   postdata=postdata,
                                   headers=headers)
            d = f.deferred
            d.addErrback(log.err)

        for callbackURI in callbacks:
            reactor.callLater(0, postNotification, callbackURI)
开发者ID:twonds,项目名称:idavoll,代码行数:35,代码来源:gateway.py

示例13: sync_dirty_attributes

def sync_dirty_attributes(queue, loop=True):
    _l = queue.qsize()
    if _l > 0:
        if loop:
            _times = min(_l, MAX_SYNC_CNT_PER_LOOP) 
        else:
            _times = _l

        i = 0
        while i < _times:
            i += 1

            try:
                attr = queue.get_nowait()
                attr.syncdb()
            except Queue.Empty:
                break
            except:
                pass

        log.info('End sync character to db, total: {0}, dirty attributes length: {1}'.format( _times, queue.qsize() ))

    if loop:
        reactor.callLater(SYNC_DB_INTERVAL, sync_dirty_attributes, queue)
    else:
        log.debug('End sync db, dirty attributes length {0}, loop:{1}'.format(
            queue.qsize(), loop))
开发者ID:anson-tang,项目名称:3dkserver,代码行数:27,代码来源:attribute.py

示例14: on_fsevent

                    def on_fsevent(evt):
                        worker.watcher.stop()
                        proto.signal('TERM')

                        if options['watch'].get('action', None) == 'restart':
                            log.msg("Restarting guest ..")
                            reactor.callLater(0.1, self.start_guest, id, config, details)
开发者ID:biddyweb,项目名称:crossbar,代码行数:7,代码来源:process.py

示例15: closedown

    def closedown(self):
        self.stopService()
        try:
            reactor.callLater(0.5,reactor.stop)
#            reactor.stop()
        except ReactorNotRunning:
            pass
开发者ID:aquamatt,项目名称:Peloton,代码行数:7,代码来源:worker.py


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