【发布时间】:2015-12-18 02:28:27
【问题描述】:
我正在使用 ZeroMQ 在两个进程之间进行数据传输:sender.py 和 receiver.py,而我现在使用的通信模式是发布者/订阅者。以下是我分别针对这两个进程的代码:
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()
实际上,代码运行良好。目前,我想在receiver.py 上做点什么:当在receiver.py 中收到data > 1000 时,它会自动终止receiver.py 和sender.py 的正在运行的脚本。我想知道我是否能够做到这一点。我真的很感谢任何建议或想法:)
【问题讨论】:
标签: python zeromq publish-subscribe