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();
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.