Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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...
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}; }
... snip...

In reply to Fork vs Win32::OLE by Fré

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (7)
    As of 2014-08-02 09:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (55 votes), past polls