in reply to ithreads picks fight with LWP::Agent; everybody loses

It works for me as posted. I added a couple of trace lines to convince myself:

[ 0:29:23.03]C:\test>670431.pl thread 1 started thread 2 started thread 3 started thread 4 started thread 5 started thread 6 started thread 7 started thread 9 started thread 8 started thread 10 started [SNIP] thread 474 ended thread 244 ended thread 239 ended thread 496 started thread 497 started thread 498 started thread 499 started If you can read this line, I have run to completion and failed to fail +. Which makes my success a failure. I'm so emo.

As you are detaching the threads, they weren't all able to complete before the main thread ended.

So rather than all that stuff above, how about posting some useful information like the versions of the modules you are using. Particularly threads


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: ithreads picks fight with LWP::Agent; everybody loses (Works for me!)
  • Download Code

Replies are listed 'Best First'.
Re^2: ithreads picks fight with LWP::Agent; everybody loses (Works for me!)
by Anonymous Monk on Feb 27, 2008 at 03:55 UTC
    He is using threads 1.69

      Perhaps he could try reverting to v1.67 (the version I have that works, albeit on a win32 build).

      He might also try the following and see if it completes clean (and post the output if not):

      #!/usr/bin/perl -w use POSIX qw[ _exit ]; use Time::HiRes qw[ usleep ]; use threads ( stack_size => 4096 ); use threads::shared; $|++; use HTTP::Request; use LWP::UserAgent; my $started :shared = 0; my $ended :shared = 0; my $monitor = async { printf "\rStarted: $started Ended: $ended\t" and uleep 100 while $ended < 500; print "\nAll done"; }; my $TEST_URL = "http://www.blairhippo.com/"; threads->create( 'execute_request', $TEST_URL )->detach for 1 ..500; $monitor->join; _exit( 0 ); sub execute_request { { lock $started; ++$started; } my $url = shift; my $request = HTTP::Request -> new ('HEAD', $url); my $agent = LWP::UserAgent -> new(); my $response = $agent -> request($request); { lock $ended; ++$ended; } }

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thanks for the code and for your help. You raise a couple of points.

        First, the premature thread termination -- yeah, I spotted that. In the real code this failure script is based off of, I do indeed take care to make sure all threads have finished before termination, so I was quite certain that wasn't the source of my trouble and left it out of this code. (Besides, on my server, the code seg faults before it ever becomes an issue.) Sorry, I should have made that clearer.

        Second, your code. I had to tweak it slightly to run (had to set stack size to 4*4096, and s/uleep/usleep/), but once it ran, it gave me a more or less instant seg fault, though in much less detail than I'm seeing in my own code:

        Started: 0 Ended: 0     Segmentation fault

        Though the "instant segfault" feature should prove valuable to my debugging, since it beats waiting for my own code to finally get around to deciding to die.

        (Whoops, I just realized I never specified that. In both my failure script and the real code, the crash isn't instantaneous; it runs a little while first. Sorry, that was relevant and should have been mentioned in my initial posting.)

        Finally, thanks for the 1.67 recommendation; I'll definitely give that a try.