【发布时间】:2017-12-01 17:48:28
【问题描述】:
我正在尝试使用以下代码将子程序从自写模块传递到线程。
这是我第一次使用线程,所以我有点不熟悉。
主脚本(缩写)
#!/usr/bin/perl -w
use strict;
use threads;
use lib 'PATH TO LIB';
use goldstandard;
my $delete_raw_files = 0;
my $outfolder = /PATH/;
my %folder = goldstandard -> create_folder($outfolder,$delete_raw_files);
&tagging if $tagging == 1;
sub tagging{
my %hash = goldstandard -> tagging_hash(\%folder);
my @threads;
foreach(keys %hash){
if($_ =~ m/mate/){
my $arguments = "goldstandard -> mate_tagging($hash{$_}{raw},$hash{$_}{temp},$hash{$_}{tagged},$mate_anna,$mate_model)";
push(@threads,$arguments);
}
if($_ =~ m/morpheus/){
my $arguments = "goldstandard -> morpheus_tagging($hash{$_}{source},$hash{$_}{tagged},$morpheus_stemlib,$morpheus_cruncher)";
push(@threads,$arguments)
}
}
foreach(@threads){
my $thread = threads->create($_);
$thread ->join();
}
}
模块
package goldstandard;
use strict;
use warnings;
sub mate_tagging{
my $Referenz = shift;
my $input = shift;
my $output_temp_dir = shift;
my $output_mate_human = shift;
my $anna = shift;
my $model = shift;
opendir(DIR,"$input");
my @dir = readdir(DIR);
my $anzahl = @dir;
foreach(@dir){
unless($_ =~ m/^\./){
my $name = $_;
my $path = $input . $_;
my $out_temp = $output_temp_dir . $name;
my $out_mate_human_final = $output_mate_human . $name;
qx(java -Xmx10G -classpath $anna is2.tag.Tagger -model $model -test $path -out $out_temp);
open(OUT, "> $out_mate_human_final");
open(TEMP, "< $out_temp");
my $output_text;
while(<TEMP>){
unless($_ =~ m/^\s+$/){
if ($_ =~ m/^\d+\t(.*?)\t_\t_\t_\t(.*?)\t_\t/) {
my $tags = $2;
my $words = $1;
print OUT "$words\t$tags\n";
}
}
}
}
}
}
sub morpheus_tagging{
my $Referenz = shift;
my $input = shift;
my $output = shift;
my $stemlib = shift;
my $cruncher = shift;
opendir(DIR,"$input");
my @dir = readdir(DIR);
foreach(@dir){
unless($_ =~ m/^\./){
my $name = $_;
my $path = $input . $_;
my $out = $output . $name;
qx(env MORPHLIB='$stemlib' '$cruncher' < '$path' > '$out');
}
}
}
1;
执行这段代码让我明白
Thread 1 terminated abnormally: Undefined subroutine &main::goldstandard -> morpheus_tagging(...) called at ... line 43.
我猜我调用踏板的方式或我提供参数的方式是错误的。我希望有人可以帮助我吗?我还在安全和不安全模块上发现了一些东西,但我不确定这是否真的是问题所在。
我猜我调用踏板的方式或我提供参数的方式是错误的。我希望有人可以帮助我吗?我还在安全和不安全模块上发现了一些东西,但我不确定这是否真的是问题。提前致谢
【问题讨论】:
-
The documentation of the
threadspragma 明确表示create的第一个参数必须是包含为线程提供代码的子例程名称的字符串,或者是对该子例程的引用。任何后续参数都作为调用参数直接传递给子例程。您已经传递了一串未编译的 Perl 代码,这不是这些选项中的任何一个。此外,goldstandard -> morpheus_tagging是一个类方法调用,它将字符串goldstandard作为第一个参数传递。
标签: multithreading perl perl-module