aboutsummaryrefslogtreecommitdiffstats
path: root/dpd/src/Adapt.py
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-10-08 18:16:51 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-10-08 18:16:51 +0200
commitfdcca6ec489537712348f01311475c98aaace9a1 (patch)
tree009a08dc86b7f78f1ceab1f55853a54e36cfa967 /dpd/src/Adapt.py
parentda5a20f2c86eef9c46a1685a51e080c3911e95ff (diff)
downloaddabmod-fdcca6ec489537712348f01311475c98aaace9a1.tar.gz
dabmod-fdcca6ec489537712348f01311475c98aaace9a1.tar.bz2
dabmod-fdcca6ec489537712348f01311475c98aaace9a1.zip
DPDCE: Use timeout to check for ZMQ RC ping
Diffstat (limited to 'dpd/src/Adapt.py')
-rw-r--r--dpd/src/Adapt.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/dpd/src/Adapt.py b/dpd/src/Adapt.py
index f7b4eb4..3fb0136 100644
--- a/dpd/src/Adapt.py
+++ b/dpd/src/Adapt.py
@@ -67,15 +67,27 @@ class Adapt:
a ZMQ socket that is in request mode (Client).
Returns a socket"""
sock = self._context.socket(zmq.REQ)
+ poller = zmq.Poller()
+ poller.register(sock, zmq.POLLIN)
+
sock.connect("tcp://%s:%d" % (self.host, self.port))
sock.send(b"ping")
- data = [el.decode() for el in sock.recv_multipart()]
- if data != ['ok']:
+ socks = dict(poller.poll(1000))
+ if socks:
+ if socks.get(sock) == zmq.POLLIN:
+ data = [el.decode() for el in sock.recv_multipart()]
+
+ if data != ['ok']:
+ raise RuntimeError(
+ "Invalid ZMQ RC answer to 'ping' at %s %d: %s" %
+ (self.host, self.port, data))
+ else:
+ sock.close(linger=10)
raise RuntimeError(
- "Could not ping server at %s %d: %s" %
- (self.host, self.port, data))
+ "ZMQ RC does not respond to 'ping' at %s %d: %s" %
+ (self.host, self.port, data))
return sock