use Parallel::ForkManager;my $pm=new Parallel::ForkManager(10); my(@cusips,@bad);$pm->run_on_finish(sub{my($pID,$exit_code,$IDent,$exit_signal,$core_dump,$var,$v)=@_;print "pID: ".$pID."\n";print " first: ".${$var}."\n"; print " second: ".${$v}."\n"; });for(1..3){$pm->start and next; # do the fork my $var=rand();my $v=rand();$pm->finish(0,$var,$v); # do the exit in the child process }$pm->wait_all_children;解决方法 只可以有一个人 :)
传递数组引用:
$pm->finish(0,[ $var,$v ]);
或哈希引用:
$pm->finish(0,{ 'var' => $var,'v' => $v });
和:
$pm->run_on_finish(sub{ my ($pID,$data)=@_; print "pID: ".$pID."\n"; print " first: ".$data->[0]."\n"; print " second: ".$data->[1]."\n"; });
要么
$pm->run_on_finish(sub{ my ($pID,$data)=@_; print "pID: ".$pID."\n"; print " first: ".$data->{'var'}."\n"; print " second: ".$data->{'v'}."\n"; });总结
以上是内存溢出为你收集整理的perl – parallel :: forkmanager …如何在退出时传递2个变量全部内容,希望文章能够帮你解决perl – parallel :: forkmanager …如何在退出时传递2个变量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)