I am trying out zmq with following codes but the subscribers are getting the objects in one after another.
Following is my PUSH script:
# zmq server -- run it once
import zmq
import time
# server
# print(zmq.Context)
ctx = zmq.Context()
sock = ctx.socket(zmq.PUSH)
sock.bind('ipc:///tmp/zmqtest')
i=0
while True:
i+=1
time.sleep(0.5)
sock.send_pyobj((i))
and the following is the PULL script:
# zmq client -- run it 2,3 times in parallel
import zmq
ctx = zmq.Context() # create a new context to kick the wheels
sock = ctx.socket(zmq.PULL)
sock.connect('ipc:///tmp/zmqtest')
i=0
while True:
i+=1
o = sock.recv_pyobj()
print('received python object:', o,i)
if o == 'quit':
print('exiting.')
break
I get following output from one of the PULL scripts:
received python object: 1 1
received python object: 3 2
received python object: 5 3
received python object: 7 4
How can I push the objects to both the scripts in parallel?
I tried PUB/SUB but it's not working this way. (can check replacing PUSH/PULL
to PUB/SUB
)