I am writing a perl script which will be run in a multiprocessing environment (basically using FORK method). However, since my script uses LWP module, and LWP module does not support multiprocessing, the script causes Perl to crash.
I am using Active Perl 5.6.
Please suggest a way out to handle the issue.
The code snippet to depict the problem is given below:
my $NumThreads = 10; print "Starting Test Cases in Threaded Environment:\n\n"; my $strRequestType = "GET"; my $strRequestUrl = "http://mohwks11232.ad.com/a.html"; my $objUserAgent = new LWP::UserAgent; my $objRequest = HTTP::Request->new($strRequestType,$strRequestUrl); # Create the requested number of threads of execution. for ($i = 1;$i <= $NumThreads; $i++) { spawnThread($i); } # Wait for all the child threads to finish and then go home. $child = 0; do { $child = wait(); } until $child == -1; print "\n Run completed successfully.\n"; # All done so go home! exit(0); sub GETResource() { print( "\nTesting BASIC (GET) authentication\n"); print( "----------------------------------"); my $objResponse = $objUserAgent->simple_request($objRequest); # This thread is all done. exit; } sub spawnThread { FORK: { if($pid = fork) { # parent process...don't do anything } elsif(defined $pid) { # We are a child thread so go do some work. GETResource(); exit; } elsif($! == EAGAIN) { #EAGAIN is the supposedly recoverable fork error sleep 5; redo FORK; } else { # unrecoverable fork error die "Fatal Error: Can't fork: $!\n"; } } }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |