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


Python reactor.callWhenRunning函数代码示例

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


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

示例1: run

    def run(self):
        self.fetchTask = self.tasks.new('Fetching data')
        self.parseTask = self.tasks.new('Parsing emails')
        self.publishTask = self.tasks.new('Creating graph')

        self.setup_twisted_logging()

        self.graph = nx.DiGraph()

        def write_graphml(stream):
            return nx.write_graphml(self.graph, stream)

        self.graph.write_graphml = write_graphml

        def stop(_):
            reactor.stop()

        def catchError(failure):
            self.error = failure

        def collect():
            d = self.asyncCollect(reactor)
            d.addErrback(catchError)
            d.addCallback(stop)

        self.error = None
        reactor.callWhenRunning(collect)
        reactor.run()

        if self.error:
            self.error.raiseException()

        return self.graph
开发者ID:GaretJax,项目名称:csat,代码行数:33,代码来源:collector.py

示例2: start_reactor

    def start_reactor(self):
        reactor.callWhenRunning(
            lambda: self.log.info('twisted-reactor-started'))

        reactor.addSystemEventTrigger('before', 'shutdown',
                                      self.shutdown_components)
        reactor.run()
开发者ID:gcgirish-radisys,项目名称:voltha,代码行数:7,代码来源:main.py

示例3: main

def main():
    install_qtreactor()
    opts, _ = parse_opts()

    start_logging(opts)
    bump_nofile_limit()
    monitor_maxrss(opts.maxrss)
    if opts.manhole:
        manhole_server()

    default_splash_server(portnum=opts.port,
                  slots=opts.slots,
                  cache_enabled=opts.cache_enabled,
                  cache_path=opts.cache_path,
                  cache_size=opts.cache_size,
                  proxy_profiles_path=opts.proxy_profiles_path,
                  js_profiles_path=opts.js_profiles_path,
                  js_disable_cross_domain_access=not opts.js_cross_domain_enabled,
                  disable_proxy=opts.disable_proxy,
                  proxy_portnum=opts.proxy_portnum)
    signal.signal(signal.SIGUSR1, lambda s, f: traceback.print_stack(f))

    from twisted.internet import reactor
    reactor.callWhenRunning(splash_started, opts, sys.stderr)
    reactor.run()
开发者ID:andresp99999,项目名称:splash,代码行数:25,代码来源:server.py

示例4: loop

    def loop(self, display, widget):
        self.display = display
        self.widget = widget
        self.global_keymap.set_next_keymap(self.widget.keymap)

        reactor.callWhenRunning(self._start_loop)
        reactor.run()
开发者ID:SapphireDensetsu,项目名称:enough,代码行数:7,代码来源:loop.py

示例5: twistedinteract

    def twistedinteract(self):
        from twisted.internet import reactor
        from twisted.internet.abstract import FileDescriptor
        import signal
        outerself = self
        class Me(FileDescriptor):
            def fileno(self):
                """ We want to select on FD 0 """
                return 0

            def doRead(self):
                """called when input is ready"""
                try:
                    outerself.handle1()
                except EOFError:
                    reactor.stop()

        reactor.addReader(Me())
        reactor.callWhenRunning(signal.signal,
                                signal.SIGINT,
                                signal.default_int_handler)
        self.prepare()
        try:
            reactor.run()
        finally:
            self.restore()
开发者ID:c0710204,项目名称:mirrorsBistu,代码行数:26,代码来源:python_reader.py

示例6: run

def run(port_num, sslport_num, proxyport_num, authproxyport_num,
        authproxy_user, verbose=True):
    root = Root(port_num, sslport_num, proxyport_num)
    factory = Site(root)
    port = reactor.listenTCP(port_num, factory)
    sslport = reactor.listenSSL(sslport_num, factory, ssl_factory())
    proxyport = reactor.listenTCP(proxyport_num, ProxyFactory())
    authproxyport = reactor.listenTCP(authproxyport_num,
                                      AuthProxyFactory(authproxy_user))

    def print_listening():
        h = port.getHost()
        s = sslport.getHost()
        p = proxyport.getHost()
        ap = authproxyport.getHost()
        print("Mock server running at http://%s:%d (http), "
              "https://%s:%d (https) and http://%s:%d (proxy) "
              "and http://%s:%d (proxy with auth, user: %s)" %
              (h.host, h.port, s.host, s.port, p.host, p.port,
               ap.host, ap.port, authproxy_user))

    if verbose:
        import sys
        from twisted.python import log
        log.startLogging(sys.stdout)
        reactor.callWhenRunning(print_listening)

    reactor.run()
开发者ID:scrapinghub,项目名称:splash,代码行数:28,代码来源:mockserver.py

示例7: shutdown

 def shutdown(reason, reactor, stopping=[]):
     """Stop the reactor."""
     if stopping: return
     stopping.append(True)
     if reason:
         log.msg(reason.value)
     reactor.callWhenRunning(reactor.stop)
开发者ID:ben-jones,项目名称:cookie-injection,代码行数:7,代码来源:proxyAndUrl.py

示例8: __exit__

 def __exit__(self, type, value, traceback):
     self._deferred.addErrback(self._handle_error)
     self._deferred.addBoth(defer.drop_param,
                            self.connection.database.disconnect)
     self._deferred.addBoth(defer.drop_param, reactor.stop)
     reactor.callWhenRunning(self._deferred.callback, self.connection)
     reactor.run()
开发者ID:f3at,项目名称:feat,代码行数:7,代码来源:tools.py

示例9: startWorkers

 def startWorkers(self):
     def _doStart():
         for i in xrange(self._maxWorkers):
             self._startWorker()
         log.debug("Registering SIGCHLD handler")
         signal.signal(signal.SIGCHLD, self._sigchldhandler)
     reactor.callWhenRunning(_doStart)
开发者ID:SteelHouseLabs,项目名称:zenoss-prodbin,代码行数:7,代码来源:workers.py

示例10: install

def install():
  def wrapNextTurn(self):
    if self not in games:
      games.append(self)
    if self.turn == self.players[0]:
      self.player1Time += self.timeInc
    elif self.turn == self.players[1]:
      self.player0Time += self.timeInc
    retval = yield aspects.proceed

  aspects.with_wrap(wrapNextTurn, Match.nextTurn)

  def tick():
    import main
    for i in games:
      if i.turn == i.players[0]:
        i.player0Time -= 1
        if i.player0Time < 0:
          i.declareWinner(i.players[1], 'Laaaaaag')
      elif i.turn == i.players[1]:
        i.player1Time -= 1
        if i.player1Time < 0:
          i.declareWinner(i.players[0], 'Laaaaaag')
      else:
        games.remove(i)

    reactor.callLater(.01, tick)

  reactor.callWhenRunning(reactor.callLater, .01, tick)
开发者ID:addiem7c5,项目名称:CS347-Rush-Hour-Project,代码行数:29,代码来源:timer.py

示例11: install

def install():
  def wrapNextTurn(self):
    if self not in games:
      games.append(self)
    if self.turn == self.players[0]:
      p = [i for i in self.objects.players]
      p[1].time += self.timeInc
    elif self.turn == self.players[1]:
      p = [i for i in self.objects.players]
      p[0].time += self.timeInc
    retval = yield aspects.proceed

  aspects.with_wrap(wrapNextTurn, Match.nextTurn)

  def tick():
    import main
    for i in games:
      p = [j for j in i.objects.values() if isinstance(j,Player)]
      if i.turn == i.players[0]:
        p[0].time -= 1
        if p[0].time < 0:
          print "2 Wins!"
          i.declareWinner(i.players[1], 'Player 1 Lagged Out, Player 2 Wins')
      elif i.turn == i.players[1]:
        p[1].time -= 1
        if p[1].time < 0:
          print "1 Wins!"
          i.declareWinner(i.players[0], 'Player 2 Lagged Out, Player 1 Wins')
      else:
        games.remove(i)

    reactor.callLater(1, tick)

  reactor.callWhenRunning(reactor.callLater, 1, tick)
开发者ID:NortySpock,项目名称:Megaminer-7,代码行数:34,代码来源:timer.py

示例12: main

def main():
    opts, _ = parse_opts()
    if opts.version:
        print(__version__)
        sys.exit(0)

    install_qtreactor(opts.verbosity >= 5)

    start_logging(opts)
    log_splash_version()
    bump_nofile_limit()
    monitor_maxrss(opts.maxrss)
    if opts.manhole:
        manhole_server()

    default_splash_server(portnum=opts.port,
                  slots=opts.slots,
                  cache_enabled=opts.cache_enabled,
                  cache_path=opts.cache_path,
                  cache_size=opts.cache_size,
                  proxy_profiles_path=opts.proxy_profiles_path,
                  js_profiles_path=opts.js_profiles_path,
                  js_disable_cross_domain_access=not opts.js_cross_domain_enabled,
                  disable_proxy=opts.disable_proxy,
                  proxy_portnum=opts.proxy_portnum,
                  filters_path=opts.filters_path,
                  allowed_schemes=opts.allowed_schemes,
                  verbosity=opts.verbosity)
    signal.signal(signal.SIGUSR1, lambda s, f: traceback.print_stack(f))

    from twisted.internet import reactor
    reactor.callWhenRunning(splash_started, opts, sys.stderr)
    reactor.run()
开发者ID:dustinthughes,项目名称:splash,代码行数:33,代码来源:server.py

示例13: main

def main():
    host, cport, mport = parse_args()
    use_codec = False

    Registry.DBPOOL = adbapi.ConnectionPool(
        'sqlite3', "sequoia/tests/auth/server_1/database.db",
        check_same_thread=False)

    mixer = AudioMixer()
    reactor.callWhenRunning(mixer.start)
    codec = speex.new() if use_codec else None
    media_tx = ServerMediaProtocol(codec, mixer)
    clients_factory = ServerClientsFactory(media_tx, use_codec)
    ctx_factory = ServerContextFactory(
        "sequoia/tests/auth/server_1/private_key.pem",
        "sequoia/tests/auth/server_1/certificate.pem",
        "sequoia/tests/auth/root/root_ca.crt")

    clients_listener = reactor.listenSSL(cport, clients_factory, ctx_factory,
        interface=host)
    show_connector_info(clients_listener, "Listening clients")
    media_listener = reactor.listenUDP(mport, media_tx,
        interface=host)
    show_connector_info(media_listener, "Serving media")

    reactor.run()
开发者ID:oblalex,项目名称:Sequoia,代码行数:26,代码来源:server.py

示例14: main

def main():
    from twisted.internet import reactor

    nanobot = NanoBot(reactor, "config.json")
    reactor.callWhenRunning(nanobot.run)
    reactor.addSystemEventTrigger("before", "shutdown", nanobot.shutdown)
    reactor.run()
开发者ID:CodeBlueDev,项目名称:nanobot,代码行数:7,代码来源:nanobot.py

示例15: handle

    def handle(self, *args, **options):  # pylint: disable=too-many-locals
        import os

        from twisted.internet import reactor

        from lava_scheduler_daemon.service import JobQueue
        from lava_scheduler_daemon.dbjobsource import DatabaseJobSource

        daemon_options = self._configure(options)

        source = DatabaseJobSource()

        if options['use_fake']:
            import lava_scheduler_app
            opd = os.path.dirname
            dispatcher = os.path.join(
                opd(opd(os.path.abspath(lava_scheduler_app.__file__))),
                'fake-dispatcher')
        else:
            dispatcher = options['dispatcher']

        # Start scheduler service.
        service = JobQueue(
            source, dispatcher, reactor, daemon_options=daemon_options)
        reactor.callWhenRunning(service.startService)  # pylint: disable=no-member
        reactor.run()  # pylint: disable=no-member
开发者ID:dl9pf,项目名称:lava-server,代码行数:26,代码来源:scheduler.py


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