Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^6: Exiting a script with an 'infinitely looping' thread

by markseger (Beadle)
on Nov 24, 2008 at 15:59 UTC ( #725621=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Exiting a script with an 'infinitely looping' thread
in thread Exiting a script with an 'infinitely looping' thread

I tried your code and it also produces the same warning. Could it be related to my version of perl? I tried both on an 5.8.0 and 5.8.5 and got the same results in both cases. I even tossed a print into the sigint handler to make sure it fired and also sleep 2 seconds before trying to exit in case I needed for the sleep in the thread to wake up. Still no luck.

# ./foo.pl
^C
A thread exited while 2 threads were running.

-mark


Comment on Re^6: Exiting a script with an 'infinitely looping' thread
Re^7: Exiting a script with an 'infinitely looping' thread
by BrowserUk (Pope) on Nov 24, 2008 at 16:08 UTC

    Upgrade!

    Certainly upgrade your threads & threads::shared to the latest cpan versions. Using the versions in any of the distributions prior to 5.8.6 (and especially 5.8.0! Are you really still using that?), is just going to give you a world of grief and no support at all.

    I'd also suggest upgrading to either 5.8.6 or waiting a few more days until 5.8.9 is released.


    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.
      re upgrade - no can do! I don't know if you ever heard of the performance monitoring tool collectl before - see http://collectl.sourceforge.net/. I'm working on some enhancements and I really need to support older versions of perl, especially since there are LOTS of users out there and I can't demand they upgrade their perl version. The thread code, which is pretty simplistic since I'm not doing anything really fancy with it, seems to be working very well except for that pesky warning.

      If detach doesn't work with older perls does that mean I have to resort to using a shared variable to tell the thread to exit? I'd really like to avoid doing that if possible.

      One other thought is that one typically runs collectl as a daemon with all the terminal I/O redirected to /dev/null so if this is really only a warning and the thread does get cleaned up, perhaps simply documenting that the message only occurs with older perl versions and can be safely ignored might be the ultimate solution.

      But wait, I just tried running the same code on a stock RHEL 5.1 system which is running perl 5.8.8 and it also produced the message, so either I need a newer perl version for the message to go away OR there is a bug in the sample that was posted.

      -mark

        ... and I really need to support older versions of perl, especially since there are LOTS of users out there and I can't demand they upgrade their perl version.

        Then document the error message saying that it is:

        1. Benign.
        2. Can be eliminated by upgrading their installs of threads & threads::shared.

        I really cannot emphasise enough how many fewer problems you will get if you use the latest of those two modules.


        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.

        If detach doesn't work with older perls does that mean I have to resort to using a shared variable to tell the thread to exit? I'd really like to avoid doing that if possible.

        You apparently have no problem with killing the threads ungracefully (->detach()). If you have no problems killing the main thread ungracefully either, just use POSIX::_exit instead of exit.

        #!/usr/bin/perl use threads; use POSIX qw( _exit ); sub worker { sleep() while 1; } $SIG{INT} = sub { _exit(0) }; my $thread = threads->create('worker')->detach(); print("Press Ctrl-C to exit\n"); sleep() while 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://725621]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-09-01 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (299 votes), past polls