我正在尝试在Perl中使用Distributed::Process框架。我已经在我的机器上成功地实现了它。但是我不知道如何使用它来运行/测试示例脚本。我尝试在#synopsis中运行代码清单
有没有人可以帮我提供一个示例脚本,以及一步一步的过程来测试它。
我想打印'Hello World‘在所有工人机器中的一个文件中...我修改了3个.pl文件,在上面的链接中可用,下面列出了。
my_worker.pl
package MyWorker;
use Distributed::Process;
use Distributed::Process::Worker;
sub run {
my $self = shift;
# do interesting stuff
open (MYFILE, '>>data.txt');
print MYFILE "Hello World\n";
close (MYFILE);
# report about what happened
$self->result("logs the results");
}my_server.pl
# Server
use Distributed::Process;
use Distributed::Process::Server;
use Distributed::Process::Master;
use MyWorker;
$master = new Distributed::Process::Master
-in_handle => STDIN, -out_handle => STDOUT,
-worker_class => 'MyWorker',
-n_workers => 2;
$server = new Distributed::Process::Server -port => 8147, -master => $master;
$server->listen();my_client.pl
# Client
use Distributed::Process;
use Distributed::Process::Client;
use MyWorker;
$client = new Distributed::Process::Client -worker_class => 'MyWorker',
-host => localhost, -port => 8147;
$client->run();然后尝试使用perl my_worker/server/client.pl (在不同的终端中)运行它。my_server和客户端引发错误,如下所示:
Can't locate MyWorker.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at my_server.pl line 5.
BEGIN failed--compilation aborted at my_server.pl line 5.我不知道如何/在哪里指定主机名,也不知道运行它的正确进程是什么
发布于 2014-06-05 02:44:24
因为您的use MyWorker;语句找不到package文件,所以您会收到该错误。
基本上,您需要将文件my_worker.pl重命名为MyWorker.pm。
此外,应该在每个perl脚本的顶部包含use strict;和use warnings。这不会直接涉及到你的问题,但如果你现在不开始做,它就会出现。
https://stackoverflow.com/questions/24039440
复制相似问题