Python Pyro4.locateNS() Examples

The following are 28 code examples of Pyro4.locateNS(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module Pyro4 , or try the search function .
Example #1
Source File: word2vecReaderUtils.py    From word2vec-twitter with MIT License 6 votes vote down vote up
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 
Example #2
Source File: utils.py    From xlinkBook with MIT License 6 votes vote down vote up
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 
Example #3
Source File: utils.py    From topical_word_embeddings with MIT License 6 votes vote down vote up
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 
Example #4
Source File: utils.py    From topical_word_embeddings with MIT License 6 votes vote down vote up
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 
Example #5
Source File: utils.py    From pynlpini with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #6
Source File: utils.py    From category2vec with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 
Example #7
Source File: utils.py    From topical_word_embeddings with MIT License 6 votes vote down vote up
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 
Example #8
Source File: utils.py    From topical_word_embeddings with MIT License 6 votes vote down vote up
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 
Example #9
Source File: utils.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
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 
Example #10
Source File: word2vecReaderUtils.py    From word2vec-twitter with MIT License 5 votes vote down vote up
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 
Example #11
Source File: utils.py    From xlinkBook with MIT License 5 votes vote down vote up
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 
Example #12
Source File: utils.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
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 
Example #13
Source File: utils.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
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 
Example #14
Source File: utils.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
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 
Example #15
Source File: utils.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
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 
Example #16
Source File: dispatcher.py    From auptimizer with GNU General Public License v3.0 5 votes vote down vote up
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') 
Example #17
Source File: pyro_server.py    From Python-Parallel-Programming-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
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() 
Example #18
Source File: utils.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
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 
Example #19
Source File: utils.py    From pynlpini with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #20
Source File: utils.py    From category2vec with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 
Example #21
Source File: proxy.py    From osbrain with Apache License 2.0 5 votes vote down vote up
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!') 
Example #22
Source File: backend.py    From synthesizer with GNU Lesser General Public License v3.0 5 votes vote down vote up
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) 
Example #23
Source File: dispatcher.py    From HpBandSter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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') 
Example #24
Source File: pyro.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def locate_nameserver():
    return Pyro4.locateNS() 
Example #25
Source File: pyro.py    From pycopia with Apache License 2.0 5 votes vote down vote up
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)) 
Example #26
Source File: pyro.py    From pycopia with Apache License 2.0 5 votes vote down vote up
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 
Example #27
Source File: worker.py    From auptimizer with GNU General Public License v3.0 4 votes vote down vote up
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) 
Example #28
Source File: worker.py    From HpBandSter with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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)