summaryrefslogtreecommitdiffstats
path: root/doc/zmq-ctrl/zmq_remote.py
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-10-08 18:09:57 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-10-08 18:09:57 +0200
commitda5a20f2c86eef9c46a1685a51e080c3911e95ff (patch)
tree8f72ded316440a213e56aee2fc0544c796f64444 /doc/zmq-ctrl/zmq_remote.py
parent72db96f56c737e613f59db8afa8f43492e0cee19 (diff)
downloaddabmod-da5a20f2c86eef9c46a1685a51e080c3911e95ff.tar.gz
dabmod-da5a20f2c86eef9c46a1685a51e080c3911e95ff.tar.bz2
dabmod-da5a20f2c86eef9c46a1685a51e080c3911e95ff.zip
zmq remote control example: use timeout on receive
Diffstat (limited to 'doc/zmq-ctrl/zmq_remote.py')
-rwxr-xr-xdoc/zmq-ctrl/zmq_remote.py42
1 files changed, 27 insertions, 15 deletions
diff --git a/doc/zmq-ctrl/zmq_remote.py b/doc/zmq-ctrl/zmq_remote.py
index 3a54b20..9e49b82 100755
--- a/doc/zmq-ctrl/zmq_remote.py
+++ b/doc/zmq-ctrl/zmq_remote.py
@@ -7,6 +7,9 @@ context = zmq.Context()
sock = context.socket(zmq.REQ)
+poller = zmq.Poller()
+poller.register(sock, zmq.POLLIN)
+
if len(sys.argv) < 2:
print("Usage: program url cmd [args...]")
sys.exit(1)
@@ -19,24 +22,33 @@ message_parts = sys.argv[2:]
print("ping")
sock.send(b"ping")
-data = sock.recv_multipart()
-print("Received: {}".format(len(data)))
-for i,part in enumerate(data):
- print(" {}".format(part))
-for i, part in enumerate(message_parts):
- if i == len(message_parts) - 1:
- f = 0
- else:
- f = zmq.SNDMORE
+socks = dict(poller.poll(1000))
+if socks:
+ if socks.get(sock) == zmq.POLLIN:
+
+ data = sock.recv_multipart()
+ print("Received: {}".format(len(data)))
+ for i,part in enumerate(data):
+ print(" {}".format(part))
+
+ for i, part in enumerate(message_parts):
+ if i == len(message_parts) - 1:
+ f = 0
+ else:
+ f = zmq.SNDMORE
+
+ print("Send {}({}): '{}'".format(i, f, part))
- print("Send {}({}): '{}'".format(i, f, part))
+ sock.send(part.encode(), flags=f)
- sock.send(part.encode(), flags=f)
+ data = sock.recv_multipart()
-data = sock.recv_multipart()
+ print("Received: {}".format(len(data)))
+ for i,part in enumerate(data):
+ print(" RX {}: {}".format(i, part))
-print("Received: {}".format(len(data)))
-for i,part in enumerate(data):
- print(" RX {}: {}".format(i, part))
+else:
+ print("ZMQ error: timeout")
+ context.destroy(linger=5)