gpt4 book ai didi

perl - 全局销毁期间的 SIG 错误

转载 作者:行者123 更新时间:2023-12-04 18:49:06 26 4
gpt4 key购买 nike

我创建的脚本有问题。这是我第一次使用信号,因为我希望我的脚本像守护进程一样运行,所以我设置了几个信号处理程序来正确结束我的脚本:

local $SIG{HUP} = \&StopSuperviser;
local $SIG{INT} = \&StopSuperviser;
local $SIG{QUIT} = \&StopSuperviser;
local $SIG{ILL} = \&StopSuperviser;
local $SIG{ABRT} = \&StopSuperviser;
local $SIG{TERM} = \&StopSuperviser;

这工作正常,但是当我将其中一个信号发送到我的脚本(Crt-C、kill -15、kill -1 ...)时,StopSuperviser 函数被正确调用,但我的脚本总是收到以下错误输出:

Argument "HUP" isn't numeric in null operation during global destruction.

我在谷歌上搜索过,但我没有找到任何处理这种行为的东西。

有人可以解释一下吗?

非常感谢您的帮助

最好的问候

佛罗伦萨

#

感谢四位的回复,这里是StopSuperviser函数:

sub StopSuperviser
{
print "On quite\n";
$StopAlarm = 1;
&DeleteThreadOrder($AllProcess);
foreach my $Subprocess (@$AllProcess) {
foreach my $thread (@{$Subprocess->{Thread}}) {
$thread->kill('USR1');
$thread->join();
}
}
exit;
}

我还使用了以下包:

use Alarm::Concurrent;

这可能很重要,也可能不重要 :)希望这有帮助:)

再次感谢您的回复和帮助

最好的问候

佛罗伦萨

最佳答案

今年早些时候我遇到了这个问题,最后在 PerlMonks 上找到了解决方案,但我现在找不到链接了。如果我遇到它,我会更新。他们的解释比我在这里介绍的要详细得多。

它是 perlsub 中描述的一个特性的表达:

If a subroutine is called using the & form, the argument list is optional, and if omitted, no @_ array is set up for the subroutine: the @_ array at the time of the call is visible to subroutine instead.

如果没记错的话,你应该可以通过更改来修复它:

local $SIG{HUP} = \&StopSuperviser;

local $SIG{HUP} = sub { StopSuperviser() };

关于perl - 全局销毁期间的 SIG 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13279600/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com