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


Python Pyro4.naming方法代碼示例

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


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

示例1: getNS

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import naming [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 naming [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 naming [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: start_local_nameserver

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import naming [as 別名]
def start_local_nameserver(host=None, port=0, nic_name=None):
	"""
		starts a Pyro4 nameserver in a daemon thread
		
		Parameters:
		-----------
			host: str
				the hostname to use for the nameserver
			port: int
				the port to be used. Default =0 means a random port
			nic_name: str
				name of the network interface to use
		
		Returns:
		--------
			tuple (str, int):
				the host name and the used port
	"""
	
	if host is None:
		if nic_name is None:
			host = 'localhost'
		else:
			host = nic_name_to_host(nic_name)

	uri, ns, _ = Pyro4.naming.startNS(host=host, port=port)
	host, port = ns.locationStr.split(':')
	
	
	thread = threading.Thread(target=ns.requestLoop, name='Pyro4 nameserver started by HpBandSter')
	thread.daemon=True
	
	thread.start()
	return(host, int(port)) 
開發者ID:automl,項目名稱:HpBandSter,代碼行數:36,代碼來源:utils.py

示例5: run

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import naming [as 別名]
def run(self):
        """
        Begin execution of the name server process and start the main loop.
        """
        self._base = cloudpickle.loads(self._base)
        try:
            Pyro4.naming.NameServer = self._base
            self._daemon = Pyro4.naming.NameServerDaemon(self.host, self.port)
        except Exception:
            self._queue.put(format_exception())
            return
        self._queue.put('STARTED')
        self._uri = self._daemon.uriFor(self._daemon.nameserver)
        self.host = self._uri.host
        self.port = self._uri.port
        self.addr = SocketAddress(self.host, self.port)
        internal_uri = self._daemon.uriFor(self._daemon.nameserver, nat=False)
        bcserver = None
        hostip = self._daemon.sock.getsockname()[0]
        # Start broadcast responder
        bcserver = BroadcastServer(internal_uri)
        sys.stdout.write(
            'Broadcast server running on %s\n' % bcserver.locationStr
        )
        sys.stdout.flush()
        bcserver.runInThread()
        sys.stdout.write(
            'NS running on %s (%s)\n' % (self._daemon.locationStr, hostip)
        )
        sys.stdout.write('URI = %s\n' % self._uri)
        sys.stdout.flush()
        try:
            self._daemon.requestLoop(lambda: not self._shutdown_event.is_set())
        finally:
            self._daemon.close()
            if bcserver is not None:
                bcserver.close()
        sys.stdout.write('NS shut down.\n')
        sys.stdout.flush() 
開發者ID:opensistemas-hub,項目名稱:osbrain,代碼行數:41,代碼來源:nameserver.py

示例6: get_my_ip

# 需要導入模塊: import Pyro4 [as 別名]
# 或者: from Pyro4 import naming [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


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