當前位置: 首頁>>代碼示例>>Python>>正文


Python Pyro4.locateNS方法代碼示例

本文整理匯總了Python中Pyro4.locateNS方法的典型用法代碼示例。如果您正苦於以下問題:Python Pyro4.locateNS方法的具體用法?Python Pyro4.locateNS怎麽用?Python Pyro4.locateNS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Pyro4的用法示例。


在下文中一共展示了Pyro4.locateNS方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getNS

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def getNS():
    """
    Return a Pyro name server proxy. If there is no name server running,
    start one on 0.0.0.0 (all interfaces), as a background process.

    """
    import Pyro4
    try:
        return Pyro4.locateNS()
    except Pyro4.errors.NamingError:
        logger.info("Pyro name server not found; starting a new one")
    os.system("python -m Pyro4.naming -n 0.0.0.0 &")
    # TODO: spawn a proper daemon ala http://code.activestate.com/recipes/278731/ ?
    # like this, if there's an error somewhere, we'll never know... (and the loop
    # below will block). And it probably doesn't work on windows, either.
    while True:
        try:
            return Pyro4.locateNS()
        except:
            pass 
開發者ID:loretoparisi,項目名稱:word2vec-twitter,代碼行數:22,代碼來源:word2vecReaderUtils.py

示例2: getNS

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def getNS():
    """
    Return a Pyro name server proxy. If there is no name server running,
    start one on 0.0.0.0 (all interfaces), as a background process.

    """
    import Pyro4

    try:
        return Pyro4.locateNS()
    except Pyro4.errors.NamingError:
        logger.info("Pyro name server not found; starting a new one")
    os.system("python -m Pyro4.naming -n 0.0.0.0 &")
    # TODO: spawn a proper daemon ala http://code.activestate.com/recipes/278731/ ?
    # like this, if there's an error somewhere, we'll never know... (and the loop
    # below will block). And it probably doesn't work on windows, either.
    while True:
        try:
            return Pyro4.locateNS()
        except:
            pass 
開發者ID:masr,項目名稱:pynlpini,代碼行數:23,代碼來源:utils.py

示例3: get_my_ip

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def get_my_ip():
    """
    Try to obtain our external ip (from the pyro nameserver's point of view)

    This tries to sidestep the issue of bogus `/etc/hosts` entries and other
    local misconfigurations, which often mess up hostname resolution.

    If all else fails, fall back to simple `socket.gethostbyname()` lookup.

    """
    import socket
    try:
        import Pyro4
        # we know the nameserver must exist, so use it as our anchor point
        ns = Pyro4.naming.locateNS()
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect((ns._pyroUri.host, ns._pyroUri.port))
        result, port = s.getsockname()
    except:
        try:
            # see what ifconfig says about our default interface
            import commands
            result = commands.getoutput("ifconfig").split("\n")[1].split()[1][5:]
            if len(result.split('.')) != 4:
                raise Exception()
        except:
            # give up, leave the resolution to gethostbyname
            result = socket.gethostbyname(socket.gethostname())
    return result 
開發者ID:loretoparisi,項目名稱:word2vec-twitter,代碼行數:31,代碼來源:word2vecReaderUtils.py

示例4: register_server

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def register_server(serverobject, host=None, port=0, unixsocket=None, nathost=None, natport=None):
    """Regiseter the server with Pycopia asyncio event handler."""
    host = host or Pyro4.config.HOST or Pyro4.socketutil.getIpAddress(socket.getfqdn())
    pyrodaemon = Pyro4.Daemon(host=host, port=port,
            unixsocket=unixsocket, nathost=nathost, natport=natport)
    uri = pyrodaemon.register(serverobject)
    ns=Pyro4.locateNS()
    ns.register("{}:{}".format(serverobject.__class__.__name__, socket.getfqdn()), uri)
    p = PyroAsyncAdapter(pyrodaemon)
    asyncio.poller.register(p)
    return p 
開發者ID:kdart,項目名稱:pycopia,代碼行數:13,代碼來源:pyro.py

示例5: get_remote

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def get_remote(hostname, servicename=None):
    """Find and return a client (proxy) give the fully qualified host name and optional servicename.
    """
    if servicename:
        patt = "{}:{}".format(servicename, hostname)
    else:
        patt = hostname
    ns = Pyro4.locateNS()
    slist = ns.list(prefix=patt)
    if slist:
        return Pyro4.Proxy(slist.popitem()[1])
    else:
        raise NameNotFoundError("Service name {!r} not found.".format(patt)) 
開發者ID:kdart,項目名稱:pycopia,代碼行數:15,代碼來源:pyro.py

示例6: locate_nameserver

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def locate_nameserver():
    return Pyro4.locateNS() 
開發者ID:kdart,項目名稱:pycopia,代碼行數:4,代碼來源:pyro.py

示例7: run

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def run(self):
		with self.discover_cond:
			t1 = threading.Thread(target=self.discover_workers, name='discover_workers')
			t1.start()
			self.logger.info('DISPATCHER: started the \'discover_worker\' thread')
			t2 = threading.Thread(target=self.job_runner, name='job_runner')
			t2.start()
			self.logger.info('DISPATCHER: started the \'job_runner\' thread')
	

			self.pyro_daemon = Pyro4.core.Daemon(host=self.host)

			with Pyro4.locateNS(host=self.nameserver, port=self.nameserver_port) as ns:
				uri = self.pyro_daemon.register(self, self.pyro_id)
				ns.register(self.pyro_id, uri)

			self.logger.info("DISPATCHER: Pyro daemon running on %s"%(self.pyro_daemon.locationStr))

		
		self.pyro_daemon.requestLoop()


		with self.discover_cond:
			self.shutdown_all_threads = True
			self.logger.info('DISPATCHER: Dispatcher shutting down')
			
			self.runner_cond.notify_all()
			self.discover_cond.notify_all()
			
			
		
			with Pyro4.locateNS(self.nameserver, port=self.nameserver_port) as ns:
				ns.remove(self.pyro_id)

		t1.join()
		self.logger.debug('DISPATCHER: \'discover_worker\' thread exited')
		t2.join()
		self.logger.debug('DISPATCHER: \'job_runner\' thread exited')
		self.logger.info('DISPATCHER: shut down complete') 
開發者ID:automl,項目名稱:HpBandSter,代碼行數:41,代碼來源:dispatcher.py

示例8: __init__

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def __init__(self, scan=True, use_pyro_ns=False, bind_localhost=False):
        self.mdb = MusicFileDatabase(scan_changes=scan)
        host = "localhost" if bind_localhost else Pyro4.socketutil.getIpAddress(None, workaround127=True)
        self.pyro_daemon = Pyro4.Daemon(host=host, port=0 if use_pyro_ns else BACKEND_PORT)
        self.pyro_uri = self.pyro_daemon.register(JukeboxBackendRemoting, "jukebox.backend")
        if use_pyro_ns:
            with Pyro4.locateNS() as ns:
                ns.register("jukebox.backend", self.pyro_uri)
        self.cli = JukeboxBackendCli(self.mdb, self.pyro_uri) 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:11,代碼來源:backend.py

示例9: locate_ns

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def locate_ns(nsaddr, timeout=3.0):
    """
    Locate a name server to ensure it actually exists.

    Parameters
    ----------
    nsaddr : SocketAddress
        The address where the name server should be up and running.
    timeout : float
        Timeout in seconds before aborting location.

    Returns
    -------
    nsaddr
        The address where the name server was located.

    Raises
    ------
    NamingError
        If the name server could not be located.
    """
    host, port = address_to_host_port(nsaddr)
    time0 = time.time()
    while True:
        try:
            Pyro4.locateNS(host, port)
            return nsaddr
        except NamingError:
            if time.time() - time0 < timeout:
                time.sleep(0.1)
                continue
            raise TimeoutError('Could not locate the name server!') 
開發者ID:opensistemas-hub,項目名稱:osbrain,代碼行數:34,代碼來源:proxy.py

示例10: get_my_ip

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def get_my_ip():
    """
    Try to obtain our external ip (from the pyro nameserver's point of view)

    This tries to sidestep the issue of bogus `/etc/hosts` entries and other
    local misconfigurations, which often mess up hostname resolution.

    If all else fails, fall back to simple `socket.gethostbyname()` lookup.

    """
    import socket

    try:
        import Pyro4
        # we know the nameserver must exist, so use it as our anchor point
        ns = Pyro4.naming.locateNS()
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect((ns._pyroUri.host, ns._pyroUri.port))
        result, port = s.getsockname()
    except:
        try:
            # see what ifconfig says about our default interface
            import commands

            result = commands.getoutput("ifconfig").split("\n")[1].split()[1][5:]
            if len(result.split('.')) != 4:
                raise Exception()
        except:
            # give up, leave the resolution to gethostbyname
            result = socket.gethostbyname(socket.gethostname())
    return result 
開發者ID:masr,項目名稱:pynlpini,代碼行數:33,代碼來源:utils.py

示例11: startServer

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def startServer():
    server = Server()
    # make a Pyro daemon
    daemon = Pyro4.Daemon()             
    # locate the name server running
    ns = Pyro4.locateNS()
    # register the server as a Pyro object
    uri = daemon.register(server)  
    # register the object with a name in the name server
    ns.register("server", uri)   
    # print the uri so we can use it in the client later
    print("Ready. Object uri =", uri)
    # start the event loop of the server to wait for calls
    daemon.requestLoop() 
開發者ID:PacktPublishing,項目名稱:Python-Parallel-Programming-Cookbook-Second-Edition,代碼行數:16,代碼來源:pyro_server.py

示例12: _run

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import locateNS [as 別名]
def _run(self):
		# initial ping to the dispatcher to register the worker
		
		try:
			with Pyro4.locateNS(host=self.nameserver, port=self.nameserver_port) as ns:
				self.logger.debug('WORKER: Connected to nameserver %s'%(str(ns)))
				dispatchers = ns.list(prefix="hpbandster.run_%s.dispatcher"%self.run_id)
		except Pyro4.errors.NamingError:
			if self.thread is None:
				raise RuntimeError('No nameserver found. Make sure the nameserver is running at that the host (%s) and port (%s) are correct'%(self.nameserver, self.nameserver_port))
			else:
				self.logger.error('No nameserver found. Make sure the nameserver is running at that the host (%s) and port (%s) are correct'%(self.nameserver, self.nameserver_port))
				exit(1)
		except:
			raise
			
			
		for dn, uri in dispatchers.items():
			try:
				self.logger.debug('WORKER: found dispatcher %s'%dn)
				with Pyro4.Proxy(uri) as dispatcher_proxy:
					dispatcher_proxy.trigger_discover_worker()

			except Pyro4.errors.CommunicationError:
				self.logger.debug('WORKER: Dispatcher did not respond. Waiting for one to initiate contact.')
				pass
			except:
				raise

		if len(dispatchers) == 0:
			self.logger.debug('WORKER: No dispatcher found. Waiting for one to initiate contact.')

		self.logger.info('WORKER: start listening for jobs')

		self.pyro_daemon = Pyro4.core.Daemon(host=self.host)

		with Pyro4.locateNS(self.nameserver, port=self.nameserver_port) as ns:
			uri = self.pyro_daemon.register(self, self.worker_id)
			ns.register(self.worker_id, uri)
		
		self.pyro_daemon.requestLoop()

		with Pyro4.locateNS(self.nameserver, port=self.nameserver_port) as ns:
			ns.remove(self.worker_id) 
開發者ID:automl,項目名稱:HpBandSter,代碼行數:46,代碼來源:worker.py


注:本文中的Pyro4.locateNS方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。