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

Python reactor.run函数代码示例

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

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



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

示例1: run

 def run():
     with LoggingContext("run"):
         logger.info("Running")
         change_resource_limit(config.soft_file_limit)
         if config.gc_thresholds:
             gc.set_threshold(*config.gc_thresholds)
         reactor.run()
开发者ID:mebjas,项目名称:synapse,代码行数:7,代码来源:federation_reader.py


示例2: run

 def run(self):
     framelog = os.path.join(self.basedir, "driver.log")
     log.startLogging(open(framelog, "a"), setStdout=False)
     log.msg("CHECK_MEMORY(mode=%s) STARTING" % self.mode)
     #logfile = open(os.path.join(self.testdir, "log"), "w")
     #flo = log.FileLogObserver(logfile)
     #log.startLoggingWithObserver(flo.emit, setStdout=False)
     d = fireEventually()
     d.addCallback(lambda res: self.setUp())
     d.addCallback(lambda res: self.record_initial_memusage())
     d.addCallback(lambda res: self.make_nodes())
     d.addCallback(lambda res: self.wait_for_client_connected())
     d.addCallback(lambda res: self.do_test())
     d.addBoth(self.tearDown)
     def _err(err):
         self.failed = err
         log.err(err)
         print err
     d.addErrback(_err)
     def _done(res):
         reactor.stop()
         return res
     d.addBoth(_done)
     reactor.run()
     if self.failed:
         # raiseException doesn't work for CopiedFailures
         self.failed.raiseException()
开发者ID:GunioRobot,项目名称:tahoe-lafs,代码行数:27,代码来源:check_memory.py


示例3: run

    def run(self):
        self.factory = HTTPFactory(
            self.channel_layer,
            self.action_logger,
            timeout=self.http_timeout,
            websocket_timeout=self.websocket_timeout,
            ping_interval=self.ping_interval,
            ws_protocols=self.ws_protocols,
            root_path=self.root_path,
        )
        # Redirect the Twisted log to nowhere
        globalLogBeginner.beginLoggingTo([lambda _: None], redirectStandardIO=False, discardBuffer=True)
        # Listen on a socket
        if self.unix_socket:
            reactor.listenUNIX(self.unix_socket, self.factory)
        elif self.file_descriptor:
            # socket returns the same socket if supplied with a fileno
            sock = socket.socket(fileno=self.file_descriptor)
            reactor.adoptStreamPort(self.file_descriptor, sock.family, self.factory)
        else:
            reactor.listenTCP(self.port, self.factory, interface=self.host)

        if "twisted" in self.channel_layer.extensions:
            logging.info("Using native Twisted mode on channel layer")
            reactor.callLater(0, self.backend_reader_twisted)
        else:
            logging.info("Using busy-loop synchronous mode on channel layer")
            reactor.callLater(0, self.backend_reader_sync)
        reactor.callLater(2, self.timeout_checker)
        reactor.run(installSignalHandlers=self.signal_handlers)
开发者ID:bibinjose22,项目名称:daphne,代码行数:30,代码来源:server.py


示例4: main

def main():
	factory = protocol.ServerFactory()      # 实例化一个ServerFactory对象
	factory.protocol = Echo     # 重写protocol

	# reactor(反应堆)就是twisted的事件驱动,是twisted的核心.
	reactor.listenTCP(1234, factory)  # 将factory回调函数注册到reactor中,reactor监听指定端口,根据状态来触发factory中不同的方法
	reactor.run()   # 启动一个TCP服务器, 监听1234端口,reactor则开始监听。
开发者ID:chenjinpeng1,项目名称:S12,代码行数:7,代码来源:twisted_echo_server.py


示例5: test_priorization

    def test_priorization(self):
        webdriver = Mock()
        settings = self.settings(WEBDRIVER_BROWSER=webdriver)
        webdriver.get.side_effect = self._wait
        webdriver.page_source = u''

        dispatcher.connect(self._stop_reactor, signal=signals.spider_closed)

        crawler = Crawler(Settings(values=settings))
        crawler.configure()
        spider = self.Spider(name='test', domain='testdomain')
        crawler.crawl(spider)
        crawler.start()
        log.start(loglevel='ERROR')
        reactor.run()

        assert webdriver.get.mock_calls == [
            call('http://testdomain/path?wr=0'),
            call('http://testdomain/path?wr=0&wa=0'),
            call('http://testdomain/path?wr=0&wa=1'),
            call('http://testdomain/path?wr=1'),
            call('http://testdomain/path?wr=1&wa=0'),
            call('http://testdomain/path?wr=1&wa=1'),
            call('http://testdomain/path?wr=0&wa=0&wr=0'),
            call('http://testdomain/path?wr=0&wa=1&wr=0'),
            call('http://testdomain/path?wr=1&wa=0&wr=0'),
            call('http://testdomain/path?wr=1&wa=1&wr=0')]
开发者ID:briscula,项目名称:shopping-robot,代码行数:27,代码来源:test_request_queue.py


示例6: main

def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('--port')
  parser.add_argument('--store')
  parser.add_argument('--retrieve')
  parser.add_argument('--connect', default=None)

  args = parser.parse_args()
  port = int(args.port)

  service = ChordService()

  if (args.connect):
    dst = args.connect.split(':')
    service.AddToRoutingTable(IPv4Address('TCP', dst[0], int(dst[1])))

  if (args.store):
    key, value = args.store.split(':')
    service.StoreValue(key, value)
    
  if (args.retrieve):
    def EchoValue(value):
      print('Retrieved value: {}.'.format(value))
    d = service.GetValue(args.retrieve)
    d.addCallback(EchoValue)

  f = pb.PBServerFactory(service)
  reactor.listenTCP(port, f)
    
  reactor.run()
开发者ID:darka,项目名称:p2pfs,代码行数:30,代码来源:chord_node.py


示例7: main

def main():
  #64bit machine builds innomitor and bitblinder
#  reactor.connectTCP('192.168.1.121', 12900, SSHFactory(LinuxInnomitorBuild()))
  reactor.connectTCP('192.168.1.121', 12900, SSHFactory(LinuxBitBlinderBuild(Globals.VERSION)))
  #32bit machine just builds innomitor
#  reactor.connectTCP('192.168.1.121', 13200, SSHFactory(LinuxInnomitorBuild()))
  reactor.run()
开发者ID:clawplach,项目名称:BitBlinder,代码行数:7,代码来源:build_all.py


示例8: run

def run(create_publisher, host='', port=80):
    """Runs a Twisted HTTP server server that publishes a Quixote
    application."""
    publisher = create_publisher()
    factory = QuixoteFactory(publisher)
    reactor.listenTCP(port, factory, interface=host)
    reactor.run()
开发者ID:pganti,项目名称:micheles,代码行数:7,代码来源:twisted_server.py


示例9: main

def main():
    from twisted.internet import reactor
    from twisted.python import log
    import logging
    log.PythonLoggingObserver().start()
    logging.getLogger().setLevel(level=logging.DEBUG)
    LOG.setLevel(level=logging.DEBUG)

    api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    api_secret = "XXXXXXXXXXXX"

    flickr = TwistedFlickrAPI(api_key, api_secret)

    #flickr.authenticate_console("write"
    #    ).addCallback(log.msg, "<- got token"
    #    ).addBoth(lambda _: reactor.callLater(0, reactor.stop)
    #    )

    #flickr.upload("test.jpg", is_public="0"
    #    ).addBoth(log.msg
    #    ).addBoth(lambda _: reactor.callLater(0, reactor.stop)
    #    )

    flickr.photos_search(user_id='[email protected]', per_page='10'
        ).addBoth(log.msg
        ).addBoth(lambda _: reactor.callLater(0, reactor.stop)
        )
    
    reactor.run()
开发者ID:bendavis78,项目名称:eyefi,代码行数:29,代码来源:twisted_flickrapi.py


示例10: poetry_main

def poetry_main():
    addresses = parse_args()

    from twisted.internet import reactor

    poems = []
    errors = []

    def got_poem(poem):
        poems.append(poem)

    def poem_failed(err):
        print >>sys.stderr, 'Poem failed:', err
        errors.append(err)

    def poem_done(_):
        if len(poems) + len(errors) == len(addresses):
            reactor.stop()

    for address in addresses:
        host, port = address
        d = get_poetry(host, port)
        d.addCallbacks(got_poem, poem_failed)
        d.addBoth(poem_done)

    reactor.run()

    for poem in poems:
        print poem
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:29,代码来源:get-poetry.py


示例11: main

def main():
    # command line processing
    process_commandline()

    call_list_server = None
    # run the call list providing web server in listening mode
    if CONFIG["LISTEN"]:
        call_list_server = CallListServer()
        site = http_server.Site(call_list_server)
        try:
            reactor.listenTCP(CONFIG["HTTP_PORT"], site, interface=CONFIG["HTTP_HOST"])
        except:
            # port could not be bound
            # (already in use, permission denied, ...)
            call_list_server = None
        else:
            dprint("running call list web server on 'http://{HTTP_HOST}:{HTTP_PORT}'".format(**CONFIG))

    # configure notifications
    enable_notifcations(
        not CONFIG["DISABLE_NOTIFICATIONS"],
        # 'All recent calls...' link only when the call list webserver
        # is running
        call_list_server,
    )

    # start the client
    reactor.connectTCP(
        CONFIG["NCID_HOST"], CONFIG["NCID_PORT"], NCIDClientFactory(reactor, CONFIG["LISTEN"], call_list_server)
    )

    # run the event dispatcher
    reactor.run()

    dprint("done.")
开发者ID:shrick,项目名称:ncidmon,代码行数:35,代码来源:ncidmon.py


示例12: getList

def getList():
    # For the sample client, below:
    from twisted.internet import reactor
    from twisted.internet.protocol import ClientCreator

    creator = ClientCreator(reactor, amp.AMP)
    host = '127.0.0.1'
    import sys
    if len(sys.argv) > 1:
        host = sys.argv[1]
    d = creator.connectTCP(host, 62308)

    def connected(ampProto):
        return ampProto.callRemote(GatewayAMPCommand, command=command)
    d.addCallback(connected)

    def resulted(result):
        return result['result']
    d.addCallback(resulted)

    def done(result):
        print('Done: %s' % (result,))
        reactor.stop()
    d.addCallback(done)
    reactor.run()
开发者ID:eventable,项目名称:CalendarServer,代码行数:25,代码来源:agent.py


示例13: nda_loop

def nda_loop():
	ndutil.setTimezone()

	ndlCom = NdlCom('nDroid-Executer', '127.0.0.1', 12322)
	ndlCom.doCom('Initiating')

	ndlCom.doCom('Loading Config')
	cnfManager = CnfManager()
	cnfManager.load('./nde.cnf')
	cnfData = cnfManager.getCnfData()

	nsQueue = Queue()
	nsLock = threading.Lock()

	netManager = NetManager()
	netManager.setNdlCom(ndlCom)
	netManager.setNsQueue(nsQueue, nsLock)

	ndlCom.doCom('Starting Threads')
	scheduler = Scheduler([ndlCom, nsQueue, nsLock], 'Scheduler')

	scheduler.start()

	reactor.listenUDP(cnfData['comPort'], netManager)
	ndlCom.doCom('Listening Com Port')
	reactor.run()

	scheduler.join()
开发者ID:jovistar,项目名称:nDroid-Executer,代码行数:28,代码来源:nde.py


示例14: run

    def run(self):
        # If umask = 0077, created files will be rw for effective user only
        # If umask = 0007, they will be rw for effective user and group only
        os.umask(self.config.umask)
        os.setegid(self.config.egid)
        os.seteuid(self.config.euid)

        # Daemonize early
        if self.daemon:
            self.lock.acquire()
            self.daemonize()

        # Do all kind of initialization
        try:
            ret = self.initialize()
        finally:
            # Tell the father how to return, and let him return (release)
            if self.daemon:
                self.state = ret
                self.lock.release()

        if ret:
            return ret

        reactor.run()
开发者ID:allgi,项目名称:mmc,代码行数:25,代码来源:agent.py


示例15: launch_stdout_downloader

def launch_stdout_downloader():

    from twisted.internet import reactor

    logging.basicConfig(level=logging.WARNING, filename="dl.log")
    if len(sys.argv) == 3:
        downloader = StdoutDownloader(int(sys.argv[2]), [])
    elif len(sys.argv) == 5:
        downloader = StdoutDownloader(int(sys.argv[2]), [(sys.argv[3], int(sys.argv[4]))])
    else:
        print "Usage: lbrynet-stdout-downloader <sd_hash> <peer_port> <dht_node_port>" \
              " [<dht_bootstrap_host> <dht_bootstrap port>]"
        sys.exit(1)

    def start_stdout_downloader():
        return downloader.start_download(sys.argv[1])

    def print_error(err):
        logging.warning(err.getErrorMessage())

    def shut_down():
        reactor.stop()

    d = task.deferLater(reactor, 0, downloader.start)
    d.addCallback(lambda _: start_stdout_downloader())
    d.addErrback(print_error)
    d.addCallback(lambda _: shut_down())
    reactor.addSystemEventTrigger('before', 'shutdown', downloader.shut_down)
    reactor.run()
开发者ID:Fillerix99,项目名称:lbry,代码行数:29,代码来源:StdoutDownloader.py


示例16: run

    def run(self, *args, **kw):
	""""""
	log.info("broker.run")
        from twisted.internet import reactor
        reactor.exitcode = 0
        reactor.run()
        return reactor.exitcode
开发者ID:BackupTheBerlios,项目名称:xenbee-svn,代码行数:7,代码来源:daemon.py


示例17: main

def main():
    global cbUrls, tsunamiUrl
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option(
        "-t",
        "--tsunami",
        dest="tsunami",
        type="string",
        default="http://127.0.0.1:9000",
        help="tsunami announce url. default: http://127.0.0.1:9000"
    )
    parser.add_option(
        "-p",
        "--port",
        dest="port",
        type="int",
        default=5000,
        help="port the RestQ demonstration resource should bind to. default: 5000"
    )
    options = parser.parse_args()[0]
    cbUrls = {
        'connect':'http://localhost:%s/connect'%options.port,
        'disconnect':'http://localhost:%s/disconnect'%options.port,
        'subscribe':'http://localhost:%s/subscribe'%options.port,
        'unsubscribe':'http://localhost:%s/unsubscribe'%options.port,
        'send':'http://localhost:%s/send'%options.port
    }
    tsunamiUrl = options.tsunami
    site = server.Site(RestQDummyResource())
    print 'running on %s'%options.port
    reactor.listenTCP(options.port, site)
    reactor.run()
开发者ID:NicolaeNMV,项目名称:Tsunami,代码行数:33,代码来源:restq_tsunami_daemon.py


示例18: wrapper

 def wrapper(*args, **kwds):
     # Ignore SIGINT to avoid it being captured in the child process
     # when pressing ctrl+c on the terminal to close the server
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     signal.signal(signal.SIGTERM, _sigterm_handler)
     f(*args, **kwds)
     reactor.run(False)
开发者ID:fuinha,项目名称:stoq-server,代码行数:7,代码来源:decorators.py


示例19: add_bank

 def add_bank(self):
     task = Administration(self.creds, "add bank", self.details)
     task.runEngine()
     try:
         reactor.run()
     except:
         pass
开发者ID:CBinyenya,项目名称:cmsserver,代码行数:7,代码来源:serverManager.py


示例20: main

def main():
    boots = (('router.bittorrent.com', 6881),)
    p = BittorrentProtocol(boots)
    # lc = LoopingCall(monitor, p)
    # lc.start(5)
    reactor.listenUDP(6881, p)
    reactor.run()
开发者ID:wjianwei126,项目名称:btcrawler,代码行数:7,代码来源:test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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