我有下面的代码。当星人服务器接收到HUP信号时,我想调用$pub->close方法。
我想清理在子进程重新启动之前,如果我不清理,子进程将阻塞。
这是我使用的.psgi文件。
use ZMQ;
use ZMQ::Constants ':all';
use Plack::Builder;
our $ctx = ZMQ::Context->new(1);
my $pub = $ctx->socket(ZMQ_PUB);
$pub->bind('tcp://127.0.0.1:5998');
# I want to close the socket and terminate the context
# when the server is restarted with kill -HUP pid
# It seems the children won't restart because the sockets isn't closed.
# The next two lines should be called before the child process ends.
# $pub->close;
# $ctx->term;
builder {
$app
}发布于 2013-01-24 15:11:37
PSGI应用程序没有标准的方法来注册每个进程清理处理程序,而且Starman似乎没有实现任何可以直接使用的东西。但你可以猴子补丁星人运行一些代码时,进程是退出。
由于Starman基于Net::Server::PreFork,并且不使用child_finish_hook()本身,您只需在.psgi文件中插入以下内容,就可以重写此Net::Server::PreFork钩子:
sub Starman::Server::child_finish_hook {
$pub->close();
$ctx->term();
}ZMQ内部使用线程来清除(或者仅仅依赖于全局析构函数)可能会以某种方式防止使用结束块,我认为最好将信号处理留给Net::Server框架。
https://stackoverflow.com/questions/14489522
复制相似问题