Fré has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
While querying churches sequentially, took literally hours, I've been trying to query them in parallel.
Every fork is supposed to generate a file-per-church.
Whereafter each file will be loaded and stored in a major hash, which would be parsed using Win32::OLE to generate an excel-doc.
Yet, it all seems to work until I load the Win32::-modules. Forking (still learning heaps about that thing) works rather the way I want it, but when I try to merge the fork-code with excel-part, then waitpid never returns.
Forking goes up until exit, but waitpid seems to wait forever.
I'm not sure how to interpret filehandles during forks, so wondering whether something remains open and locking the fork.
I'm bound to use ActiveState Perl 5.6(.1?).
Here's how I tried it.
snipsnip...
While querying churches sequentially, took literally hours, I've been trying to query them in parallel.
Every fork is supposed to generate a file-per-church.
Whereafter each file will be loaded and stored in a major hash, which would be parsed using Win32::OLE to generate an excel-doc.
Yet, it all seems to work until I load the Win32::-modules. Forking (still learning heaps about that thing) works rather the way I want it, but when I try to merge the fork-code with excel-part, then waitpid never returns.
Forking goes up until exit, but waitpid seems to wait forever.
I'm not sure how to interpret filehandles during forks, so wondering whether something remains open and locking the fork.
I'm bound to use ActiveState Perl 5.6(.1?).
Here's how I tried it.
snipsnip...
... snip...use warnings; use strict; #use Win32::OLE; #use Win32::OLE qw(in with); #use Win32::OLE::Variant; #use Win32::OLE::Const 'Microsoft Excel'; use POSIX; use Time::Local; use IPC::Open3; use File::Copy; use File::stat; use Getopt::Std; use Time::Local; use Data::Dumper; my $EXCEL; $SIG{__DIE__} = sub { $EXCEL->Quit() if (defined($EXCEL)); print "Died +: "; CORE::die @_ }; $SIG{__WARN__} = sub { die "Warning-SIG caught: ".$_[0] }; select STDERR; $|=1; select STDOUT; $|=1; my $starttime=localtime(); print "------ $starttime ---------------"; my @BLIST=("floep","flap"); my %proclist; foreach my $boxnr (@BLIST) { $proclist{$boxnr}=fork(); if ($proclist{$boxnr}== 0) { my $rc=0; print "Starting child ($$) for box $boxnr."; $rc=system("qu +ery.pl $boxnr"); print "Succesfull Query (fork: $rc=>$?) for box $boxnr...\n"; exit 0; } else { print "Child generated: PPID: $$ - Fork: $proclist{$boxnr}\n +"; } } foreach my $proc (keys(%proclist)) { print "Waiting to end... "; my $porki=waitpid($proclist{$proc},0); print "Porki: $porki - $proc\n"; } foreach my $file (@files) { local $/=""; my $boxnr=substr($file,0,index($file,"_")); print "($boxnr) File: ".$file."\n"; open FH,"<$file" or die "File-issue: $file\n"; my $tempstring=<FH>; close FH; my %hash=%{eval "$tempstring"}; $BOX{$boxnr}=$hash{$boxnr}; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Fork vs Win32::OLE
by nikosv (Deacon) on Jan 23, 2013 at 13:05 UTC |
Back to
Seekers of Perl Wisdom