Created
December 15, 2010 08:18
-
-
Save kamipo/741766 to your computer and use it in GitHub Desktop.
Parallel::PreforkとParallel::ForkManagerのちがい。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use Parallel::ForkManager; | |
| my @all_data = qw/hoge fuga foo bar fizz buzz/; | |
| my $pm = new Parallel::ForkManager(3); | |
| for my $data (@all_data) { | |
| $pm->start and next; | |
| sleep 1; | |
| warn "data: $data\n"; | |
| $pm->finish; | |
| } | |
| $pm->wait_all_children; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use Parallel::Prefork; | |
| my @all_data = qw/hoge fuga foo bar fizz buzz/; | |
| my $pm = Parallel::Prefork->new({ | |
| max_workers => 3, | |
| trap_signals => { | |
| TERM => 'TERM', | |
| HUP => 'TERM', | |
| } | |
| }); | |
| while ($pm->signal_received ne 'TERM' and @all_data) { | |
| my $data = shift @all_data; | |
| $pm->start and next; | |
| sleep 1; | |
| warn "data: $data\n"; | |
| $pm->finish; | |
| } | |
| $pm->wait_all_children; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment