Hello Monks,
I am very new to threads. I have a well built script running properly.It takes too long to process. So i want to use threads.Below is my script on a small scale."Free to wrong pool a4b73c0 not b3bf050 at C:/strawberry/perl/site/lib/Parallel/ForkManager.pm line 498, <FH> line 6." error and perl.exe stops saying encountered a problem.
Any help is really appreciated.
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::Pane;
use WWW::Mechanize;
use Web::Scraper;
use Data::Dumper;
use Parallel::ForkManager;
my $mw = tkinit();
$mw->geometry('300x300+100+100');
my $sp = $mw->Scrolled('Pane',-scrollbars=>'osoe',sticky=>'nwse')->pac
+k(-expand=>1,-fill=>'both');
$sp->Label(-text=>"Give Keyword file")->pack();
my $entry1 = $sp->Entry()->pack();
my $showbutton = $mw->Button(-text=>'Submit',
-command =>\&button_callback)->pack();
my $bimage = scraper {
process "img" , "url[]" => '@src';
};
sub button_callback {
my $filename = $entry1->get();
open FH, $filename or die $!;
my $mech = WWW::Mechanize->new;
my $manager = new Parallel::ForkManager(10);
while (my $line = <FH>) {
$manager->start and next;
chomp($line); my @temp = split(/ /,$line); my $query = join('+',@tem
+p);
my $ibing = "http://www.bing.com/images/search?count=10&q=".$query;
$mech->get($ibing);
#print Dumper $mech->content;
my $res = $bimage->scrape($mech->content,$mech->uri);
print Dumper $res;
$manager->finish;
$manager->wait_all_children;
}
close (FH);
}
MainLoop();