Here is my code:
--------------------------------------- perl1.pl --------------------------------------- use strict; use warnings; use v5.8; use threads; use threads::shared; use HTTP::Cookies; use LWP::UserAgent; use HTTP::Request::Common qw(POST); use HTTP::Request::Common qw(POST $DYNAMIC_FILE_UPLOAD); use URI::Escape; use perl_module1; ##################################################### # main() ##################################################### print("Starting LetsRock() \n"); LetsRock(); print("LetsRock() ended \n"); exit(0); ###################################################################### +############################# # LetsRock ###################################################################### +############################# sub LetsRock { my (@kids); for (my $x=0; $x < 5; $x++) { my ($kid) = Thread(\&ThreadFunc, 'https://www.wellsfargo.com') +; if (defined($kid)) { push(@kids, $kid); } sleep(1); } WaitForThreads(@kids); } ###################################################################### +############################# # ThreadFunc ###################################################################### +############################# sub ThreadFunc { my ($url) = @_; GetIt($url); } ###################################################################### +####### # Function: int Thread(ref function, string[] params) # # Description: # Spawn a thread to execute the specified function with optiona +l parameters # # Scope: public # # Parameters: # ref function - reference to function to call in thread # string[] params - optional params to pass to function # # Possible return values: id of spawned thread or undef ###################################################################### +####### sub Thread { my ($function, @params) = @_; my ($thread); if (defined(&{$function})) { $thread = threads->create($function, @params); } return($thread); } ###################################################################### +####### # Function: void WaitForThreads(int[] threads) # # Description: # Wait for all threads to end and return # # Scope: public # # Parameters: # int[] threads - array of thread ids # # Possible return values: none ###################################################################### +####### sub WaitForThreads { my (@threadArray) = @_; print("WaitForThreads() started \n"); foreach my $thread (@threadArray) { print("waiting for " . $thread->tid . "\n"); $thread->join(); } print("WaitForThreads() finished \n"); } ###################################################################### +####### # Function: void WaitForThread(int thread) # # Description: # Wait for a thread to end and return # # Scope: public # # Parameters: # int thread - thread id # # Possible return values: none ###################################################################### +####### sub WaitForThread { my ($thread) = @_; $thread->join; } --------------------------------------- perl_module1.pm --------------------------------------- package perl_module1; use strict; use v5.8; use HTTP::Cookies; use LWP::UserAgent; #use HTTP::Request::Common qw(POST); 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; ###################################################################### +# # GetIt ###################################################################### +# 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(); } } 1;
--------------------------------------- Here's my stack trace after the exception:
---------------------------------------

libeay32.dll!02858123()
ssleay32.dll!028055db()
ssleay32.dll!0280216e()
SSLeay.dll!027e1408()
perl58.dll!28041ee4()
perl58.dll!28060417()
perl58.dll!28025e9c()
perl58.dll!28025d44()
perl58.dll!28025ca4()
ntdll.dll!7c82f9dd()
msvcrt.dll!77bbcef6()
perl58.dll!280625fd()
perl58.dll!28067553()
perl58.dll!28067b2a()
perl58.dll!28062086()
perl58.dll!28062016()
perl58.dll!28061fb4()
perl58.dll!28023b0d()
perl58.dll!28023a23()
perl58.dll!28067897()
threads.dll!003e1158()
threads.dll!003e12be()
perl58.dll!28066e41()
threads.dll!003e1c60()
threads.dll!003e2322()
perl58.dll!28041ee4()
perl58.dll!28060417()
perl58.dll!28025e9c()
perl58.dll!28025d44()
perl58.dll!28025ca4()
perl58.dll!280625fd()
perl58.dll!28067553()
perl58.dll!28067b2a()
perl58.dll!28067814()
perl58.dll!28067b2a()
perl58.dll!28001bb5()
perl58.dll!28061a6b()
perl58.dll!280606c6()
perl58.dll!28041260()
perl58.dll!28060417()
perl58.dll!280257ac()
perl58.dll!28025663()
perl58.dll!2802550c()
perl58.dll!2808c909()
perl58.dll!2808c918()
ntdll.dll!7c832b78()
ntdll.dll!7c832b7f()
kernel32.dll!77e68e4c()
ntdll.dll!7c82fb23()
msvcrt.dll!77bbd08c()
msvcrt.dll!77bcbe2a()
perl.exe!00401012()
perl.exe!004010f9()
kernel32.dll!77e523cd()

Environment:
Windows 2003
Activestate Perl v5.8.7 built for MSWin32-x86-multi-thread
ActivePerl-Config 0.1: up to date.
ActivePerl-DocTools 1.0: up to date.
ActiveState-Utils 1.23: up to date.
ActiveState-WSProxy 1.8: up to date.
Archive-Tar 1.26.0.1: up to date.
Archive-Zip 1.16: up to date.
Compress-Zlib 1.41: up to date.
Crypt-SSLeay 0.51: up to date.
DBD-mysql 3.0002: up to date.
DBI 1.49: new version 1.50 available in ActiveState Package Repository
Data-Dump 1.6: up to date.
Digest-HMAC 1.1: up to date.
Digest-MD2 2.3: up to date.
Digest-MD4 1.5.0.1: up to date.
Digest-SHA1 2.10: up to date.
File-CounterFile 1.4: up to date.
Font-AFM 1.19: up to date.
HTML-Parser 3.46: up to date.
HTML-Tagset 3.4: up to date.
HTML-Tree 3.18: up to date.
IO-String 1.7: up to date.
IO-Zlib 1.4: up to date.
MD5 2.3: up to date.
MIME-Base64-Scripts 1.0: up to date.
NTLM 1.02: up to date.
SOAP-Lite 0.55.0.1: up to date.
Term-ReadLine-Perl 1.2.3.2: new version 1.0203 available in ActiveState Package Repository
TermReadKey 2.30: up to date.
Text-Autoformat 1.13: up to date.
Text-Reform 1.11: up to date.
Tk 804.27.0.4: up to date.
URI 1.35: up to date.
Unicode-String 2.9: up to date.
WebService-Perl 0.03: up to date.
XML-Parser 2.34.0.1: up to date.
XML-Simple 2.14: up to date.
libwww-perl 5.803.0.1: up to date.

The exception happens when returning from the LetsRock() function.

Edit: g0n - readmore tags


In reply to Threads calling LWP causes exception by mojoshaneman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.