Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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.

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 $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é

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (8)
    As of 2018-06-22 11:30 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (124 votes). Check out past polls.