multithreading - Why can't URI object locate method "scheme"? -
i trying create asynchronous http request client using next source code:
#!perl utilize uri; utilize ddp; utilize threads; utilize thread::queue; utilize lwp::useragent; utilize constant num_workers => 25; $req_q = thread::queue->new(); $res_q = thread::queue->new(); @urls = ( "http://google.com", "http://web.de" ); @workers; ( 1 .. num_workers ) { force @workers, async { $ua = lwp::useragent->new(); while ( $req = $req_q->dequeue() ) { $res_q->enqueue( $ua->request($req) ); } }; } $url (@urls) { $req_q->enqueue( http::request->new( => $url ) ); } $req_q->enqueue(undef) @workers; ( 1 .. @urls ) { $res = $res_q->dequeue(); p $res; } $_->join() @workers;
unfortunately receive error:
400 can't locate object method "scheme" via bundle "uri::http"
this should uri
module issue if utilize uri bundle in other scripts works fine.
i tried upgrade uri uri-1.64 (upgraded 1.60) tested on fedora (x86_64 gnu/linux) perl 5.16 , on ubuntu (i686 athlon i386 gnu/linux) perl 5.14.
e.g
$perl -muri -e'say $inc{"uri.pm"}; uri->version; uri->new("http://www.google.com/")->scheme' $/home/xxxxx/perl5/lib/perl5/uri.pm $1.64 $http
any thought best way troubleshoot?
the original code used thread::queue::any instead of thread::queue since handles objects bit better. however, there 2 mistakes in original code (now fixed).
use thread::queue::any 1.03 qw( ); ... $req_q = thread::queue->new(); $res_q = thread::queue->new();
should be
use thread::queue::any 1.03; # must phone call import. ... $req_q = thread::queue::any->new(); $res_q = thread::queue::any->new();
thread::queue::any work in import
shouldn't there, customary practice of not calling import
backfired.
these minor changes allow code work.
if wanted go on using thread::queue, looks have load modules of shared objects before phone call use threads;
(i think that'll save memory, it's thought no matter what.) uri dynamically loads uri::http, need add together
use uri::http;
or
begin { uri->new('', 'http') }
before use threads;
that passed problem (and another).
multithreading perl http asynchronous
No comments:
Post a Comment