in reply to fork/threads: running after childrem

The problem I can see in your code is that you are not waiting for the last children to exit before writing to the log file. I would write is as follows:
#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; use Proc::Queue size => 3, qw(run_back waitpids); my $starttime = time; my $user_agent = LWP::UserAgent->new; $user_agent->timeout(30); my @urlstoget = qw( http://foo.com http://bar.com http://etc.com http: +//and-so-on.com ); my @pids; for my $url (@urlstoget) { push @pids, run_back { my $request = HTTP::Request->new('GET', $url); my $response = $user_agent->request($request); my $dbh = connectdb('listeningpost'); processresponse($response) }; } waitpids(@pids); my $elapsed = time - $starttime; open LOG, ">", "getitemshtmlog.txt" or die "unable to open log file"; print LOG "$n urls in $elapsed seconds, ",$elapsed/$n," sec per url\n" +;

If this version doesn't work yet, it could be a bug on Proc::Queue, in that case send the author (=> me) a bug report with your full script or post it here.

Replies are listed 'Best First'.
Re^2: fork/threads: running after childrem
by cormanaz (Deacon) on Apr 09, 2007 at 23:16 UTC
    Thank you that did it.

    BTW I built the questionable code based on the example code at CPAN . The code you just gave would make a better example, IMO.