Closed pevogam closed 6 years ago
ns_server.register()
right before where you create the DaemonLoop. So it's no surprise it doesn't react to the call.I first expected some symmetry between the pyro daemon and the name server in the request loop vs registration ordering, therefore my first guest was the one above, but I assume this difference (in comment lines below) is related to implementation details. For reference, rearranged and working version is:
import Pyro4
Pyro4.config.AUTOPROXY = False
Pyro4.config.REQUIRE_EXPOSE = False
# pyro daemon
try:
pyro_daemon = Pyro4.Daemon(host=host)
logging.debug("Pyro4 daemon started successfully")
pyrod_running = False
# address already in use OS error
except OSError:
pyro_daemon = Pyro4.Proxy("PYRO:" + Pyro4.constants.DAEMON_NAME + "@" + host)
pyro_daemon.ping()
logging.debug("Pyro4 daemon already started, available objects: %s",
pyro_daemon.registered())
pyrod_running = True
# name server
try:
ns_server = Pyro4.locateNS(host=host, port=port)
logging.debug("Pyro4 name server already started")
nsd_running = True
# network unreachable and failed to locate the nameserver error
except (OSError, Pyro4.errors.NamingError):
from Pyro4 import naming
ns_uri, ns_daemon, _bc_server = naming.startNS(host=host, port=port)
ns_server = Pyro4.Proxy(ns_uri)
logging.debug("Pyro4 name server started successfully with URI %s", ns_uri)
nsd_running = False
# local_object = ...
# we should register to the pyro daemon before entering its loop
uri = pyro_daemon.register(local_object)
loop = None
if not pyrod_running:
loop = DaemonLoop(pyro_daemon)
loop.start()
elif not nsd_running:
loop = DaemonLoop(ns_daemon)
loop.start()
# we should register to the name server after entering its loop
ns_server.register(object_name, uri)
Regarding the second and more important point, the working version showed me that I could invoke multiple daemons each using different ports and registering objects at the name server so there is no need to access the same daemon. I hope the use case is clear though - sometimes it could be useful to dynamically generate remote objects (possibly at different times during a long process) that cannot all be registered and made available before the request loop or from a single deployed script. Of course, the security risks of rogue objects registered at a privileged daemon should be considered very carefully.
Thank you for following up and posting the solution to your issue, much appreciated.
Hi, what is the best way to register objects for remote access at an already running Pyro daemon and name server? I have the following code with the object of registering new remote modules and starting the two daemon loops if not already started:
However, calling
ns_server.register
via the proxy results in indefinite hanging during connection establishing. Am I missing something obvious? Is there a better and simpler way to achieve this?This is the precise stack trace I am getting:
Thanks!