本文整理汇总了Python中Pyro4.Proxy方法的典型用法代码示例。如果您正苦于以下问题:Python Pyro4.Proxy方法的具体用法?Python Pyro4.Proxy怎么用?Python Pyro4.Proxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pyro4
的用法示例。
在下文中一共展示了Pyro4.Proxy方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_connection
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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
示例2: test_compat_layer
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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"
示例3: initialize
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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
示例4: __init__
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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?")
示例5: initialize
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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!')
示例6: initialize
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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!')
示例7: get_remote
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [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))
示例8: get_proxy
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
def get_proxy(uri):
return Pyro4.Proxy(uri)
示例9: __init__
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
def __init__(self, name, uri):
self.name = name
self.proxy = Pyro4.Proxy(uri)
self.runs_job = None
示例10: connect_backend
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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)
示例11: init_with_parameters
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
def init_with_parameters(self, *args, **kwargs):
"""
Method that gets called, after getting the Proxy object from the server.
Overwrite, if needed.
"""
pass
示例12: __init__
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [as 别名]
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()
示例13: _run
# 需要导入模块: import Pyro4 [as 别名]
# 或者: from Pyro4 import Proxy [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)