Erlang:抵御港口所有者死亡的鲁棒性
当拥有生成端口的进程死亡并由主管重新启动时会发生什么?
有没有办法让旧港口不与主人同归于尽,让新主人“接管”?
如果做不到这一点,是否可以确保生成的进程在其端口死亡时终止?
What happens when the process which owns a spawned port dies and is restarted by the supervisor?
Is there a way for the old port not to die with its owner and for the new owner to "take over"?
Failing that, is it possible to ensure that the spawned process terminates when its port dies?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,请注意,您不希望端口所有者死亡。因此,将任何“危险”代码移至另一个进程,并使端口所有者尽可能愚蠢。这是 Erlang 的错误缓解方式。现在,如果该进程终止,则情况确实很糟糕,因此在这种情况下,回收该端口可能也是明智之举。但既然我们把所有东西都搬走了,我们就指望这种情况不会发生。
关于 2,端口将在终止时发送特定消息,因此您可以安排生成的进程优雅地检测到这一点并终止它。请参阅
http://www.erlang.org/doc/reference_manual/ports.html
First, notice that you don't want the port owner to die. So move any "dangerous" code out to another process and make the port owner as dumb as possible. This is error-mitigation the Erlang way. Now, if that process dies, something is really bad, so in that case it may be clever to recycle the port as well. But since we moved everything out, we are counting on that not happening.
Regarding 2, the port will send a specific message when it terminates, so you can arrange for your spawned process to gracefully detect this and terminate with it. See
http://www.erlang.org/doc/reference_manual/ports.html