Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

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


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

Time for some code and here's what I'm doing. I still get the message. Gotta be some thing silly (I hope)

#!/usr/bin/perl -w

use threads;
$SIG{"INT"}=\&sigInt;

my $thread=threads->create('test')->detach();

while(1) { sleep 100; }

sub test { sleep 100; }

sub sigInt { exit; }

-mark


Comment on Re^4: Exiting a script with an 'infinitely looping' thread
Re^5: Exiting a script with an 'infinitely looping' thread
by BrowserUk (Pope) on Nov 24, 2008 at 15:27 UTC
      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

        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.

      Due to Perl "safe signals", sleep is an uninteruptable opcode

      The docs and my observations disagree.

      #!/usr/bin/perl $\ = "\n"; $SIG{INT} = sub { print "SIGINT" }; print time; sleep(); # Sleep forever print time;
      1227543323 SIGINT 1227543325

      Safe signals means that the handler is only called after sleep returns, but sleep returns as soon as a signal is received.

      The behaviour differs in Windows, but then again, there are no signals in Windows.

        The behaviour differs in Windows, ...

        Exactly. You know what I use...

        but then again, there are no signals in Windows.

        And yet:

        C:\test>perl -wle"1 while 1" Terminating on signal SIGINT(2) C:\test>perl -wle"1 while 1" Terminating on signal SIGBREAK(21)

        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-09-23 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls