in reply to Re^2: Threads calling LWP causes exception
in thread Threads calling LWP causes exception

Hmm. I'm using 5.8.6 and a simplified version of your script (simplified to try and track down where the scalar was being leaked from), and google also gives me no problems:

C:\test>535553 http://google.com Starting LetsRock() Waiting for 1 Waiting for 2 Waiting for 3 Waiting for 4 Waiting for 5 LetsRock() ended

Perhaps you could try my code and see what results you get?

package perl_module1; use strict; use v5.8; use HTTP::Cookies; use LWP::UserAgent; use HTTP::Request::Common; use URI::Escape; use vars qw(@ISA @EXPORT); use Exporter (); our @ISA = qw(Exporter); our @EXPORT = qw( GetIt ); our $DEBUG = 0; sub GetIt { my ($url) = @_; my ($ua) = LWP::UserAgent->new(keep_alive => 1); $ua->timeout(60); # allow redirects for POST push @{ $ua->requests_redirectable }, 'POST'; # set the cookie my ($cookie) = './ac_cookie.txt' . $$; $ua->cookie_jar(HTTP::Cookies->new('file' => $cookie)); my ($response) = $ua->get($url); if ($response->is_success) { my ($page) = $response->content; # print( $page ); } else { printf "Failed with %s\n", $response->message; } } return 1 if caller; package main; use strict; use warnings; use v5.8; use threads; use threads::shared; print("Starting LetsRock() \n"); LetsRock( $ARGV[ 0 ] ); print("LetsRock() ended \n"); exit(0); sub LetsRock { my $url = shift; my (@kids); for (my $x=0; $x < 5; $x++) { my ($kid) = threads->create( \&ThreadFunc, $url ); if (defined($kid)) { push(@kids, $kid); } sleep(1); } printf "Waiting for %s\n", $_->tid, $_->join for @kids; } sub ThreadFunc { return perl_module1::GetIt( $_[0] ); } __END__

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Threads calling LWP causes exception
by mojoshaneman (Novice) on Mar 10, 2006 at 05:24 UTC
    Your code works. I tried changing my code to look more like yours but have not been successful. The code sample I gave was an example of the bug I'm seeing in a much large set of code. Any ideas why this code works and the sample I gave does not?

      I just re-downloaded your code and ran it as is except for commenting out the empty print statement in the GetIt() subroutine and taking the url from the command line.

      It runs fine (except for the leaked scalars which are an unrelated problem), on my system now I have installed Crypt::SSLeay:

      C:\test>perl1 https://www.wellsfargo.com Starting LetsRock() WaitForThreads() started waiting for 1 waiting for 2 waiting for 3 waiting for 4 waiting for 5 WaitForThreads() finished Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 Scalars leaked: 1 LetsRock() ended

      as I suggested elsewhere, I'd try grabbing a fresh copy of Crypt::SSLeasy from the Theory5 respoitory and if that doesn't work, install AS5.8.6. Beyond that, it's difficult to suggest anything without being able to reproduce teh error.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.