Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Is this Proc::Queue error

by chanakya (Friar)
on Dec 06, 2006 at 14:55 UTC ( #588097=perlquestion: print w/replies, xml ) Need Help??

chanakya has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a script which forks 3 childs at a given time and this is taken care by Proc::Queue.
Everything worked fine until I moved the line "next if" above the Proc::Queue::run_back_now{} method

After the above change the script spawns unlimited childs. For example, I have an array of 50 files
the script spawns 50 childs.

Is this the problem of Proc::Queue or is this script error. Below is my code
#!/usr/bin/perl -w use POSIX 'WNOHANG'; use Proc::Queue ':all'; use Getopt::Long 'GetOptions'; my $numChilds=3; GetOptions( 'childs|c=i' => \$opt_numChilds , 'help|h' => \&USAGE ) || USAGE() ; ($opt_numChilds) ? $numChilds=$opt_numChilds : $numChilds; Proc::Queue::size($numChilds); #update my $src="/data/files"; my @allfiles = ("$src/file1", "$src/file2", "$src/file3","$src/file4", +"$src/file5","$src/file6"); my $log = "/tmp/data.log"; open(STAT, $log) || die ("Can't open file $log: $!"); my @pids; foreach my $file (@allfiles) { my ($root=$file); ($root=$file)=~tr/a-z/A-Z/; next if (!-f"$srcdir/ok"); push @pids, Proc::Queue::run_back_now{ #code here system(" -file $file > file.err 2>&1"); }; } waitpids(@pids); close STAT; exit;
Many thanks

Replies are listed 'Best First'.
Re: Is this Proc::Queue error
by johngg (Canon) on Dec 06, 2006 at 15:36 UTC
    I don't think your processing of $opt_numChilds is doing what you think. Instead of

    my $numChilds=3; ... ($opt_numChilds) ? $numChilds=$opt_numChilds : $numChilds;


    my $numChilds = $opt_numChilds ? $opt_numChilds : 3;

    Your code gives a "Useless use of private variable in void context" message.



Re: Is this Proc::Queue error
by salva (Canon) on Dec 06, 2006 at 16:01 UTC
    You have to use run_back instead of run_back_now.

    The *_now functions ignore (on purpose) the limit on the number of childs that can be forked.

Re: Is this Proc::Queue error
by derby (Abbot) on Dec 06, 2006 at 15:11 UTC

    I'm no expert on Proc::Queue but should you either do use Proc::Queue size => 3 or call Proc::Queue::size(3)? I'm not seeing how your numChilds is affecting Proc::Queue.

Re: Is this Proc::Queue error
by chanakya (Friar) on Dec 06, 2006 at 15:16 UTC

    I missed posting the line Proc::Queue::size($numChilds);
    I have updated the code with the missing line

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://588097]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2023-02-02 17:55 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (20 votes). Check out past polls.