python - Python 中的 ZMQ - PULL 端进程能否知道 PUSH 端进程是否已关闭?

标签 python subprocess zeromq distributed-computing pyzmq

我在 python 中使用 ZMQ 通过 PUSH-PULL 在主应用程序和 worker 子进程之间分配计算.

有时,主进程可能会崩溃,而子进程仍然挂起,监听各自的端口。

我尝试使用 atexit 来在主节点崩溃的情况下关闭 worker,如 this SO question 中所建议的那样.但是 atexit 没有捕捉到我强行关闭 master 时的情况。

有没有办法让 PULL-side worker 子进程注意到 PUSH- side master 是通过 zmq sock 关闭的(可能暗示了 here )?

实用解决方案(编辑)

我实现的一个实用解决方案是让 master PUSH 关闭所有挂起的 worker 当它重新启动时:

在生成自己的助手之前,master 的新实例会向所有套接字广播一个exit 消息。

收到退出命令后,挂起的子进程(由 master 的前一个实例启动)执行 sys.exit()

最佳答案

答:没有,但是有变通办法

如果唯一PUSH-PULL:

Scaleable Formal Ccommunication P模式仍然存在,那么答案就没有别的了选项是但是:不,不能


但 ZeroMQ 是一个强大的分布式处理概念的思想转变

然而,随着一些轻微的架构转变,所需的功能来自其他正式通信模式,与初始的 PUSH-PULL 单独部署.

enter image description here

共存的 TransportPLANE(s) + SIG_PLANE(s) 行为编排仅受个人想象力的限制。


虽然没有直接解决您的[dead-man button] 信号方案 的代码,this answer illustrates the possible approaches in this direction by focusing on co-existing BEHAVIOUR(s) rather than on code.

关于python - Python 中的 ZMQ - PULL 端进程能否知道 PUSH 端进程是否已关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35113243/

相关文章:

python - PyDev 项目中输入的 undefined variable

python - 通过 python 子进程 sshing 后终端挂起

c++ - 当通过 tcp 接收编码图像的消息时,zmq 在第二个循环中崩溃

python - AlchemyAPI 编译时出错

使用 Protocol Buffer 的 Python 项目,部署问题

python - 对具有不等长子列表的数组应用简单操作

python - 从 python 启动和停止外部进程

python - 使用 pexpect 获取 'ls' 命令的输出

tcp - 为什么 Windows7 上的 TCP/IP 需要 500 次发送才能预热? (w10,w8 证明没有受到影响)

使用protobuf序列化消息与zeromq进行通信