Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

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


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

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


Comment on Re^8: Exiting a script with an 'infinitely looping' thread
Re^9: Exiting a script with an 'infinitely looping' thread
by BrowserUk (Pope) on Nov 24, 2008 at 16:57 UTC
    ... 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.
Re^9: Exiting a script with an 'infinitely looping' thread
by ikegami (Pope) on Nov 24, 2008 at 17:36 UTC

    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://725629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2014-12-29 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (187 votes), past polls