-
-
Save leobalter/779cbaa8a4da1e7a0148c475ab822d65 to your computer and use it in GitHub Desktop.
This file contains 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 5.8.8; | |
use IO::Handle; | |
use FindBin; | |
use Config; | |
my $Bin; | |
BEGIN { | |
$ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1; | |
unshift @INC, "$FindBin::Bin"; | |
unshift @INC, "$FindBin::Bin/lib"; | |
unshift @INC, "$FindBin::Bin/local/lib/perl5"; | |
unshift @INC, "$FindBin::Bin/local/lib/perl5/$Config{archname}"; | |
$ENV{LOAD_ROUTES} = 1; | |
} | |
use Parallel::ForkManager; | |
use Socket; | |
use DDP; | |
my $processes = 4; | |
my $pm = Parallel::ForkManager->new($processes); | |
my @files = ('a'..'z'); | |
# Almost there, but hell don't ever execute this | |
socketpair(my $rdr, my $wtr, AF_UNIX, SOCK_STREAM, PF_UNSPEC); | |
sub getFile { | |
my $file = shift @files; | |
if ($file) { | |
return $file . "\n"; | |
} | |
} | |
while (my $file = getFile()) { | |
print $wtr $file; | |
} | |
# Open each process | |
FILES: | |
for (my $i = 0; $i < $processes; $i++) { | |
my $pid = $pm->start() and next FILES; | |
while (chomp(my $line = <$rdr>)) { | |
sleep(.1); | |
print "$i: $line\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