gpt4 book ai didi

multithreading - Parallel::ForkManager fork 后只有一个事件线程。为什么?

转载 作者:行者123 更新时间:2023-12-01 06:28:46 26 4
gpt4 key购买 nike

通过 Parallel::Fork fork 后,我只有一个工作线程:

ps -ef | grep ./BuildReportIndexV_VR2.pl

503 15955 9531 18 13:11 pts/0 00:02:06 /usr/bin/perl ./BuildReportIndexV_VR2.pl promt_tenant=AD backward=1
503 16102 15955 99 13:13 pts/0 00:09:29 /usr/bin/perl ./BuildReportIndexV_VR2.pl promt_tenant=AD backward=1
503 16103 15955 0 13:13 pts/0 00:00:02 /usr/bin/perl ./BuildReportIndexV_VR2.pl promt_tenant=AD backward=1
503 16104 15955 0 13:13 pts/0 00:00:02 /usr/bin/perl ./BuildReportIndexV_VR2.pl promt_tenant=AD backward=1
503 16105 15955 0 13:13 pts/0 00:00:03 /usr/bin/perl ./BuildReportIndexV_VR2.pl promt_tenant=AD backward=1

进程 15955 是父进程,16102 及以下进程是子进程。

这是相关的代码:
my $pm = Parallel::ForkManager->new($MAX_PROCESSES);
$pm->set_max_procs( $MAX_PROCESSES );

my $start_index;
my $last_index;

for ( $start_index = 0,
$last_index=$start_index+$subhash_size-1;

$last_index <= keys %$index_hr;

$start_index=$last_index+1, $last_index=$start_index+$subhash_size-1
)
{
$pm->start and next;
create_report_subprocess( $index_hr, $start_index, $last_index );
$pm->finish;
}
$pm->wait_all_children;

print "After all children are waited: last index: $last_index\n";
if ( $last_index > keys %$index_hr) {
$last_index = keys %$index_hr;
create_report_subprocess( $index_hr, $start_index, $last_index );
}

我设置了 $MAX_PROCESSES=4。

我预计所有 4 个线程都在运行。为什么只有一个?

最佳答案

尝试设置 AutoInactiveDestroy对于 for 循环之前的任何事件数据库或语句句柄。

关于multithreading - Parallel::ForkManager fork 后只有一个事件线程。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25229047/

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