Search code examples
pythonpyro

Checking if Pyro remote objects are reachable


I have a one Pyro server running in each of my VMs. These are all the same objects, and I'm just running them to ensure reliability. I'd like to be able to monitor whether these objects are "alive" and reachable or not.

Assuming I have their URIs, how can I check that without trying to run a method of the actual object to see if it runs?

One option is to write a simple noop method in these objects, call it remotely and if there's a connection issue I'd know the object is not reachable.

Is there a built-in way to do this in Pyro? Seems like a common enough use-case.


Solution

  • You don't have to add a noop / ping method to your objects, because you can use the _pyroBind() method on a proxy object for this. It will raise a CommunicationError if the object is not reachable. For example to see if the name server is running on port 9999:

    import Pyro4
    import Pyro4.errors
    
    with Pyro4.Proxy("PYRO:Pyro.NameServer@localhost:9999") as p:
        try:
            p._pyroBind()
            print("YEP IT IS RUNNING!")
        except Pyro4.errors.CommunicationError:
            print("NOPE IT IS NOT REACHABLE!")