【发布时间】:2015-10-30 22:20:21
【问题描述】:
我有一个使用 threads 的多线程 perl 脚本,工作正常,但是当它试图杀死挂起的线程时,我收到错误并且脚本存在:
for (0..$threads-1) {
$trl[$_] = threads->create(\&my_sub, $_);
$SIG{ALRM} = sub {
if ($trl->is_running) {
$trl->kill('ALRM');
}
}
}
for (@trl) {
alarm 10;
$_->join;
}
和
sub my_sub {
$SIG{ALRM} = sub {
threads->exit(1);
};
while (@site) {
{
lock(@site);
$url = shift @site;
}
和错误:
Can't call method "is_running" on an undefined value at test.pl line 61.
Perl exited with active threads:
9 running and unjoined
40 finished and unjoined
0 running and detached
第 61 行是:
if ($trl->is_running) {
【问题讨论】:
标签: perl