Perl uchun multiprocessing moduli bormi?

Perl uchun multiprocessing moduli bormi? Pythonning multiprocessing module tomonidan taqdim etilgan narsalarga o'xshash funksiyalarga ega bo'lgan narsa.

Men shunga o'xshash funksiyani Perl yordamida qurishim mumkinligini tushunaman, ammo amalga oshirilgan narsalarni qidiraman.

11
@PlatinumAzure "

Uzoq masofadagi qismi uchun portativ bir ajralmaslik mavjudligini bilmayman.

qo'shib qo'ydi muallif Sinan Ünür, manba
Fork() ga qo'shimcha ravishda (sizning Perl ushbu qo'llab-quvvatlash uchun tuzilgan deb hisoblasa) ish zarrachalari mavjud. "Perlthrtut" ga qarang DOC
qo'shib qo'ydi muallif JRFerguson, manba
Ha, men bu savolga qo'shib qo'yganman.
qo'shib qo'ydi muallif jkysam, manba
Perl ning fork va exec qutisidan tashqarida ekanligini unutmang.
qo'shib qo'ydi muallif Platinum Azure, manba
@ SinanÜnür Albatta, albatta.
qo'shib qo'ydi muallif Platinum Azure, manba
CPAN, shuningdek, Parallel :: Pvm - Perl kengaytmasi uchun parallel Virtual Kalkulyator (PVM) Message Passing tizimi . Menda tajriba yo'q. Siz izlayotgan masofaviy jarayon boshqaruviga o'xshaydi.
qo'shib qo'ydi muallif MetaEd, manba
Agar men masofadagi parallellikni talab qilsam, Gearman :: XS kabi narsalarga qarashni boshlayman. Mahalliy bo'lsa, u holda fork/exec yoki parallel :: ForkManager jarayonlarni boshqarishi mumkin.
qo'shib qo'ydi muallif runrig, manba

3 javoblar

Forks :: Super deb o'ylayman juda yaqin. Fon jarayonida o'zboshimchalik bilan subroutini (yoki tashqi buyruqni) bajarish, fon jarayonini kuzatish va signalizatsiya qilish va jarayoni biroz pastroq qilish uchun bir nechta xususiyatlarga ega.

use Forks::Super;

sub do_something { my @args = @_; ... }
$process = fork { sub => \&do_something, args => [@args] };
$process->wait;


my $x = 42;
my @y = ();
my %z = ();
sub do_something_else {
    $x = 19;
    @y = qw(foo bar);
    %z = (foo => 'bar');
}
$process = fork { sub => 'do_something_else', share => [\$x, \@y, \%z ] };
$process->wait;
# $x, @y, and %z are now updated with changes made in background process


# create your own pipes to use for IPC
use IO::Handle;
pipe my $child_read, my $parent_write;
pipe my $parent_read, my $child_write;
$parent_write->autoflush(1);
$child_write->autoflush(1);
sub square {
    while (my $x = <$child_read>) {
        print {$child_write} $x ** 2, "\n";
    }
    close $child_write;
}
$process = fork { sub => 'square' };
print {$parent_write} "9\n";
my $result = <$parent_read>;    # should be "81\n";
close $parent_write;

# or use the standard I/O handles for IPC
sub square_root {
    sleep 1 && seek STDIN,0,1 while eof(STDIN); # ok, this is a workaround for an existing bug :-(
    while (my $x = ) {
        print sqrt($x), "\n";
    }
}
$process = fork { sub => 'square_root', child_fh => 'in,out,block' };
$process->write_stdin("81\n");
$result = $process->read_stdout(); #  =>  "9\n"

multiprocessing moduli va Forks :: Super da juda ko'p xususiyat mavjud. Siz qaysi biri bilan qiziqasiz?

Men Forks :: Super muallifiman va mening maqsadim odamlarning foydali topishi uchun parallel ishlov berish uchun har qanday funktsiyalarni kiritishdir, shuning uchun siz istagan multiprocessing Perl, menga xabar bering.

11
qo'shib qo'ydi
Bu men izlayotgan narsa. Men bu vazifani bizda mavjud bo'lgan "Perl" skriptlarida ishlash vaqtlarini takomillashtirish uchun parallelizmni qo'shmoqdaman. Men oldin Pythonning juda ko'p mahsulotlarini ishlatganman, lekin Perlda bunga o'xshash narsa yo'q. Skriptlarni aylantirishni boshlaganimda, men aniqroq savollar beraman.
qo'shib qo'ydi muallif jkysam, manba
Uh, bu modul mening Perl-ga o'rnatiladimi-yo'qligini tekshirib ko'rdim, va, ehtimol, bu emas. Men shunga o'xshash muhim narsalarni xohlardimki, bu standart Perl paketining bir qismi edi. :(
qo'shib qo'ydi muallif antred, manba

forks provides the same awesome interface as threads, but uses processes instead of threads.

use forks;  # Or: use threads;
use Thread::Queue;

my $q = Thread::Queue->new();

my @workers;
for (1..NUM_WORKERS) {
   push @workers, async {
      while (defined(my $job = $q->dequeue())) {
         ...
      }
   };
}

$q->enqueue(...);

$q->enqueue(undef) for @workers;
$_->join for @workers;

Forks bilan Supero'tkazgichlarni solishtirish.

Esingizda bo'lsa, bular Forks :: Super excels!

use Forks::Super;
sub do_something { my @args = @_; ... }
$process = fork { sub => \&do_something, args => [@args] };
$process->wait;

kabi yozilishi mumkin

use forks;
sub do_something { my @args = @_; ... }
$process = async { do_something(@args) };
$process->join;

---

use Forks::Super;
my $x = 42;
my @y = ();
my %z = ();
sub do_something_else {
    $x = 19;
    @y = qw(foo bar);
    %z = (foo => 'bar');
}
$process = fork { sub => 'do_something_else', share => [\$x, \@y, \%z ] };
$process->wait;

kabi yozilishi mumkin

use forks;
use forks::shared;
my $x :shared = 42;
my @y :shared = ();
my %z :shared = ();
sub do_something_else {
    $x = 19;
    @y = qw(foo bar);
    %z = (foo => 'bar');
}
$process = async { do_something_else() };
$process->join;

---

use Forks::Super;
use IO::Handle;
pipe my $child_read, my $parent_write;
pipe my $parent_read, my $child_write;
$parent_write->autoflush(1);
$child_write->autoflush(1);
sub square {
    while (my $x = <$child_read>) {
        chomp($x);
        print {$child_write} $x ** 2, "\n";
    }
    close $child_write;
}
$process = fork { sub => 'square' };
print { $parent_write } "9\n";
chomp( my $result = <$parent_read> );  # 81
close $parent_write;
$process->wait;

kabi yozilishi mumkin

use forks;
use Threads::Queue;
my $req = Threads::Queue->new();
my $resp = Threads::Queue->new();
sub square { $_[0] ** 2 }
$process = async {
    while (defined(my $x = $req->dequeue())) {
        $resp->enqueue( square($x) );
    }
};
$req->enqueue(9);
my $result = $resp->dequeue();  # 81
$resp->enqueue(undef);
$process->join;

---

use Forks::Super;
sub square_root {
    sleep 1 && seek STDIN,0,1 while eof(STDIN); # ok, this is a workaround for an existing bug :-(
    while (my $x = ) {
        chomp($x);
        print sqrt($x), "\n";
    }
}
$process = fork { sub => 'square_root', child_fh => 'in,out,block' };
$process->write_stdin("81\n");
chomp( $result = $process->read_stdout() );  # 9
$process->close_fh('stdin');
$process->wait;

kabi yozilishi mumkin

use forks;
use Threads::Queue;
my $req = Threads::Queue->new();
my $resp = Threads::Queue->new();
$process = async {
    while (defined(my $x = $req->dequeue())) {
        $resp->enqueue( sqrt($x) );
    }
};
$req->enqueue(81);
my $result = $resp->dequeue();  # 9
$resp->enqueue(undef);
$process->join;
10
qo'shib qo'ydi
@ jkysam, vilkalar va Forks :: Super.
qo'shib qo'ydi muallif ikegami, manba

POE: Perl ob'ekt muhiti haqida nima deyish mumkin? Asnxronli bola jarayonlarini qo'llab-quvvatlaydi.

3
qo'shib qo'ydi