The best way to check whether a service is running is to try making an RPC call to it :)
This is the behaviour when services/methods don't exist:
If you call a method that doesn't exist on a running service, you'll get a MethodNotFound error.
If you call a service that isn't running and has never previously run you'll get an UnknownService error.
If you call a method on a service that is not currently running, the RpcProxy will wait for a reply (which would be sent when the service comes back online) or a timeout to expire.
Your situation is the third one, so you need a timeout.
Is the ClusterRpcProxy in your code the one from nameko.standalone.rpc? If so I think you just need to pass the timeout as a keyword argument:
with ClusterRpcProxy({'AMQP_URI': "amqp://..."}, timeout=2) as rpc:
...
You might be using
flask-nameko instead, in which case there's probably some other way to configure timeouts. But certainly a timeout is what you need, and once it's configured correctly the proxy won't hang. The reason it hangs in the nameko shell is that the proxy there doesn't have any RPC timeout configured by default.