I am using ZeroMQ for data transmission between two processes: sender.py
and receiver.py
, and the communication pattern I'm using now is Publisher/Subscriber. The following is my code for both processes, respectively:
sender.py:
import zmq
context = zmq.Context()
publisher = context.socket(zmq.PUB)
# Set SNDHWM to not drop messages for slow subscribers
publisher.sndhwm = 1100000
publisher.bind("tcp://127.0.0.1:%s" % "5555")
for i in range(10000):
publisher.send(i)
receiver.py
import zmq
context = zmq.Context()
subscriber = context.socket(zmq.SUB)
subscriber.connect("tcp://127.0.0.1:%s" % "5555")
subscriber.setsockopt(zmq.SUBSCRIBE, "")
while(True):
data = subscriber.recv()
Actually, the code works fine. Currently, I want to do something on receiver.py
: When received data > 1000
in receiver.py
, it automatically terminates the running scripts for both receiver.py
and sender.py
. I wonder if I'm able to do that. I really appreciate for any suggestions or ideas :)