Python Pyro4.Proxy() Examples

The following are 23 code examples of Pyro4.Proxy(). 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: rpc.py    From MCVirt with GNU General Public License v2.0 6 votes vote down vote up
def get_connection(self, object_name, password=None):
        """Obtain a connection from pyro for a given object."""
        # Obtain a connection to the name server on the localhost
        nameserver = Pyro4.naming.locateNS(host=self.__host,
                                           port=self.NS_PORT, broadcast=False)

        class AuthProxy(Pyro4.Proxy):
            """Create an auth proxy that appends specfic handshake data."""

            def _pyroValidateHandshake(self, data):  # Override upstream # noqa
                """Override upstream handshake."""
                self._pyroHandshake[Annotations.SESSION_ID] = data

        # Create a Proxy object, using the overriden Proxy class and return.
        proxy = AuthProxy(nameserver.lookup(object_name))
        proxy._pyroHandshake = self._get_auth_obj(password=password)
        proxy._pyroBind()
        return proxy 
Example #2
Source File: unit_test_utils.py    From DL4MT with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def initialize(model_options, pyro_port, pyro_name, pyro_key):
    if model_options['dim_per_factor'] is None:
        if model_options['factors'] == 1:
            model_options['dim_per_factor'] = [model_options['dim_word']]
        else:
            sys.stderr.write('Error: if using factored input, you must specify \'dim_per_factor\'\n')
            sys.exit(1)

    assert (len(model_options['dictionaries']) == model_options['factors'] + 1)
    # one dictionary per source factor + 1 for target factor
    assert (len(model_options['dim_per_factor']) == model_options['factors'])
    # each factor embedding has its own dimensionality
    assert (sum(model_options['dim_per_factor']) == model_options[
        'dim_word'])  # dimensionality of factor embeddings sums up to total dimensionality of input embedding vector

    # load dictionaries and invert them
    worddicts = [None] * len(model_options['dictionaries'])
    for ii, dd in enumerate(model_options['dictionaries']):
        worddicts[ii] = load_dict(dd)

    if model_options['n_words_src'] is None:
        n_words_src = len(worddicts[0])
        model_options['n_words_src'] = n_words_src
    if model_options['n_words'] is None:
        n_words = len(worddicts[1])
        model_options['n_words'] = n_words

    print 'Initilizing remote theano server'
    # In order to transfer numpy objects across the network, must use pickle as Pyro Serializer.
    # Also requires various environment flags (PYRO_SERIALIZERS_ACCEPTED, PYRO_SERIALIZER)
    #   for both name server and server.
    Pyro4.config.SERIALIZER = 'pickle'
    Pyro4.config.NS_PORT = pyro_port
    remote = Pyro4.Proxy("PYRONAME:{0}".format(pyro_name))
    remote._pyroHmacKey = pyro_key

    remote.init(model_options)
    return remote 
Example #3
Source File: lda_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to `worker.initialize()`).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        import Pyro4
        with utils.getNS() as ns:
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lda_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lda_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i at %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.warning("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lda_worker scripts on your machines first!') 
Example #4
Source File: lsi_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to worker.initialize()).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        with utils.getNS() as ns:
            import Pyro4
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lsi_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lsi_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i from %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.exception("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lsi_worker scripts on your machines first!') 
Example #5
Source File: lda_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to `worker.initialize()`).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        import Pyro4
        with utils.getNS() as ns:
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lda_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lda_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i at %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.warning("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lda_worker scripts on your machines first!') 
Example #6
Source File: lsi_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to worker.initialize()).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        with utils.getNS() as ns:
            import Pyro4
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lsi_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lsi_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i from %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.exception("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lsi_worker scripts on your machines first!') 
Example #7
Source File: lda_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to `worker.initialize()`).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        import Pyro4
        with utils.getNS() as ns:
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lda_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lda_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i at %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.warning("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lda_worker scripts on your machines first!') 
Example #8
Source File: pyro_dataset.py    From MedicalDataAugmentationTool with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, uri, *args, **kwargs):
        """
        Gets the server dataset at the given URI and stops and starts its threads.
        :param uri: URI to connect to.
        :param args: Arguments passed to init_with_parameters.
        :param kwargs: Keyword arguments passed to init_with_parameters.
        """
        self.uri = uri
        self.server_dataset = Pyro4.Proxy(self.uri)
        restart_threads = True  # not self.server_dataset.initialized_with_same_parameters(args, kwargs)
        if restart_threads:
            self.server_dataset.stop_threads()
        self.server_dataset.init_with_parameters(*args, **kwargs)
        if restart_threads:
            self.server_dataset.start_threads() 
Example #9
Source File: pyro_dataset.py    From MedicalDataAugmentationTool with GNU General Public License v3.0 5 votes vote down vote up
def init_with_parameters(self, *args, **kwargs):
        """
        Method that gets called, after getting the Proxy object from the server.
        Overwrite, if needed.
        """
        pass 
Example #10
Source File: dispatcher.py    From auptimizer with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, name, uri):
		self.name = name
		self.proxy = Pyro4.Proxy(uri)
		self.runs_job = None 
Example #11
Source File: box.py    From synthesizer with GNU Lesser General Public License v3.0 5 votes vote down vote up
def connect_backend(self, try_nameserver=True):
        def backend_connected(backend):
            playtime = datetime.timedelta(seconds=backend.total_playtime)
            status = "Connected to backend @ {0:s} | number of tracks: {1:d} | total playtime: {2}"\
                     .format(backend._pyroUri.location, backend.num_tracks, playtime)
            self.show_status(status, 5)
        if try_nameserver:
            # first try if we can find a backend in a name server somewhere
            self.backend = Pyro4.Proxy("PYRONAME:jukebox.backend")
            try:
                self.backend._pyroBind()
                return backend_connected(self.backend)
            except Pyro4.errors.PyroError:
                pass
        try:
            # try a local backend
            self.backend = Pyro4.Proxy("PYRO:jukebox.backend@localhost:{0}".format(BACKEND_PORT))
            self.backend._pyroBind()
            return backend_connected(self.backend)
        except Exception as x:
            self.show_status("ERROR! Connection to backend failed: "+str(x))
            answer = tkinter.messagebox.askokcancel("Connect backend",
                                                    "Cannot connect to backend. Maybe it is not started.\n\n"
                                                    "Do you want me to start the backend server?")
            if answer:
                p = subprocess.Popen([sys.executable, "-m", "jukebox.backend", "-noscan", "-localhost"])
                self.backend_process = p.pid
                self.after(2000, self.connect_backend, False) 
Example #12
Source File: dispatcher.py    From HpBandSter with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, name, uri):
		self.name = name
		self.proxy = Pyro4.Proxy(uri)
		self.runs_job = None 
Example #13
Source File: pyro.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def get_proxy(uri):
    return Pyro4.Proxy(uri) 
Example #14
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 #15
Source File: lda_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to `worker.initialize()`).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        import Pyro4
        with utils.getNS() as ns:
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lda_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lda_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i at %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.warning("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lda_worker scripts on your machines first!') 
Example #16
Source File: lsi_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to worker.initialize()).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        with utils.getNS() as ns:
            import Pyro4
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lsi_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lsi_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i from %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.exception("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lsi_worker scripts on your machines first!') 
Example #17
Source File: lda_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to `worker.initialize()`).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        import Pyro4
        with utils.getNS() as ns:
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lda_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lda_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i at %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.warning("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lda_worker scripts on your machines first!') 
Example #18
Source File: lsi_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to worker.initialize()).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        with utils.getNS() as ns:
            import Pyro4
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lsi_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lsi_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i from %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.exception("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lsi_worker scripts on your machines first!') 
Example #19
Source File: lda_dispatcher.py    From topical_word_embeddings with MIT License 5 votes vote down vote up
def initialize(self, **model_params):
        """
        `model_params` are parameters used to initialize individual workers (gets
        handed all the way down to `worker.initialize()`).
        """
        self.jobs = Queue(maxsize=self.maxsize)
        self.lock_update = threading.Lock()
        self._jobsdone = 0
        self._jobsreceived = 0

        # locate all available workers and store their proxies, for subsequent RMI calls
        self.workers = {}
        import Pyro4
        with utils.getNS() as ns:
            self.callback = Pyro4.Proxy('PYRONAME:gensim.lda_dispatcher') # = self
            self.callback._pyroOneway.add("jobdone") # make sure workers transfer control back to dispatcher asynchronously
            for name, uri in ns.list(prefix='gensim.lda_worker').iteritems():
                try:
                    worker = Pyro4.Proxy(uri)
                    workerid = len(self.workers)
                    # make time consuming methods work asynchronously
                    worker._pyroOneway.add("requestjob")
                    worker._pyroOneway.add("exit")
                    logger.info("registering worker #%i at %s" % (workerid, uri))
                    worker.initialize(workerid, dispatcher=self.callback, **model_params)
                    self.workers[workerid] = worker
                except Pyro4.errors.PyroError:
                    logger.warning("unresponsive worker at %s, deleting it from the name server" % uri)
                    ns.remove(name)

        if not self.workers:
            raise RuntimeError('no workers found; run some lda_worker scripts on your machines first!') 
Example #20
Source File: quiz-controller.py    From networkzero with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(QuizController, self).__init__(*args, **kwargs)
        self.setWindowTitle("Quiz Controller")

        self.instructions = Pyro4.Proxy("PYRO:quiz.instructions@localhost:1234")
        self.responder = FeedbackReader(Pyro4.Proxy("PYRO:quiz.feedback@localhost:1234"))
        self.responder.message_received.connect(self.handle_response)
        self.responder.start()

        overall_layout = QtGui.QVBoxLayout()
        self.add_teams(overall_layout)

        self.panel_layout = QtGui.QHBoxLayout()
        self.panels = {}
        for position in "left", "right":
            panel = self.panels[position.lower()] = Panel(self, position)
            self.panel_layout.addWidget(panel)
        overall_layout.addLayout(self.panel_layout)
        self.add_controller(overall_layout)
        self.setLayout(overall_layout)

        #
        # The first response is always lost. Not sure why.
        #
        self.send_command("COLOURS?")
        self.send_command("COLOURS?")
        self.send_command("SCORES?")
        self.send_command("TEAMS?") 
Example #21
Source File: test_pyro4compat.py    From Pyro5 with MIT License 5 votes vote down vote up
def test_compat_layer():
    from Pyro4 import naming
    from Pyro4 import socketutil
    from Pyro4 import util
    try:
        _ = 1//0
    except ZeroDivisionError:
        tb = util.getPyroTraceback()
        assert len(tb) == 3
        assert "Traceback" in tb[0]
        assert "zero" in tb[2]
    assert 4 == socketutil.getIpVersion("127.0.0.1")
    assert 6 == socketutil.getIpVersion("::1")
    Pyro4.URI("PYRO:test@localhost:5555")
    p = Pyro4.Proxy("PYRO:test@localhost:5555")
    Pyro4.BatchProxy(p)
    Pyro4.Daemon()
    assert socketutil.getIpAddress("localhost", ipVersion=4).startswith("127.0")
    if socket.has_ipv6:
        try:
            assert ":" in socketutil.getIpAddress("localhost", ipVersion=6)
        except socket.error as x:
            if str(x) != "unable to determine IPV6 address":
                raise
    assert "127.0.0.1" == socketutil.getIpAddress("127.0.0.1")
    assert "::1" == socketutil.getIpAddress("::1")
    assert "127.0.0.1" == socketutil.getInterfaceAddress("127.0.0.1")
    with pytest.raises(NotImplementedError):
        naming.NameServer()
    with pytest.raises(NotImplementedError):
        _ = p._pyroHmacKey
    with pytest.raises(NotImplementedError):
        p._pyroHmacKey = b"fail" 
Example #22
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) 
Example #23
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)