Windows & fork are like windows & stones; mix them and some thing's gonna break :)
Try this (slightly tested):
#! perl -slw use strict; use threads; use threads::shared; use LWP::Simple; use HTML::TreeBuilder::XPath; sub locked(\$) :lvalue { lock ${$_[0]}; ${$_[0]} } our $T //= 3; my $stdoutSem :shared; my $running :shared = 0; while( my $url = <> ) { chomp $url; async { ++locked( $running ); if( my $content = get $url ) { my $tree = HTML::TreeBuilder::XPath->new(); $tree->parse( $content ); # do some processing here on the content if( my $title = $tree->findnodes( '/html/head/title' ) ) { chomp $title; lock $stdoutSem; print "$url : $title "; } # once done then delete the root node $tree->delete(); } --locked( $running ); }->detach; Win32::Sleep 500 while $running >= $T; }
And use it like this:
thisScript.pl urls.list > output.file
In reply to Re: Perl crashing with Parallel::ForkManager and WWW::Mechanize
by BrowserUk
in thread Perl crashing with Parallel::ForkManager and WWW::Mechanize
by NeonFlash
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |