I am trying to create an asynchronous http request client using the following source code:
#! Ural use of Pearl; Use DDP; Use threads; Use thread: line; Use LWP :: UserAgent; Use continuous NUM_WORKERS & gt; 25; My $ req_q = Thread :: line- & gt; new (); My $ res_q = Thread :: Qi-> New (); My @urls = ("http://google.com", "http://web.de"); My @Workers; (1. NUM_WORKERS) {Push @Workers, async {my $ ua = LWP :: UserAgent- & gt; new (); While (my $ req = $ req_q-> dequeue ()) {$ res_q- & gt; Enquee ($ ua- & gt; Request ($ req)); }}; } {$ Req_q-> for my $ url (@urls) Enque (HTTP :: Request-> New (GET => $ url)); } $ Req_q- & gt; For the undefined @workers; (1 .. @ curl) for {my $ res = $ res_q- & gt; Dequeue (); P $ res; } $ _- & gt; Join () for @workers; Unfortunately, I get an error: 400 package "URI :: HIT"
This should be a module issue, But if I use the URI package in other scripts then it works fine.
I tested the URI on URI-16Fedora (x86_64 GNU / Linux) Pearl 5.16 and Ubuntu (i686 atllon ION 6GNU / Linux) Pearl 5.14.
e.g.
$ perl -MURI -E'say $ INC {"URI.pm"}; URI- & gt; VERSION; URI- & gt; New ("http://www.google.com/") - & gt; Plan '$ / home / xxxxx / perl5 / lib / perl5 / URI.pm $ 1.64 $ http
What would be the best way to troubleshoot any idea?
Thread :: Queue :: Thread: Anyone instead of the line because these objects A little handles are better However, there were two mistakes in the original code (now fixed).
Usage Thread :: Line :: Any 1.03 qw (); ... my $ req_q = thread :: line- & gt; new (); My $ res_q = Thread :: Qi-> New ();
should be
Usage Thread :: Line :: Any 1.03; # Import should call ... my $ req_q = thread :: qi :: any- & gt; new (); My $ res_q = thread :: line: any-> new ();
Thread :: Qi :: Anybody works in This minor change will allow the code to work. If Thread :: wants to continue using the queue, it seems that you have to load the module before using the or First use the This will pass you to that problem (and in the other). Import
, which should not be there, so do not call calling my phone customary practice Import
thread before calling your shared objects. ;
(I think that will save you memory, so it does not matter that there is a good idea to do this.) URI URI: Loads the HTI, so you Use URI: http;
BEGIN {URI-> New ('', 'http')}
thread;
Comments
Post a Comment