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

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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^8: Exiting a script with an 'infinitely looping' thread
by ikegami (Patriarch) on Nov 24, 2008 at 17:18 UTC

    I meant at the OS level. What you see is Perl's emulation of signals. And as there usually is with emulations, there are incompatibilities in the behaviour of the emulated signals. That it doesn't work in Windows has nothing to do with safe signals, and all to do with a flawed emulation of sleep.

      That it doesn't work in Windows has nothing to do with safe signals,...

      On no?

      Try this (on a Windows system and perl 5.8.x using a cmd.exe exe console and a standard 101-key ps2-compatible keyboard configured for UK, on a Monday in November; shortly after 5.00 pm with a tail wind and a little good luck...)

      C:\test>set PERL_SIGNALS=safe C:\test>perl -wle"$SIG{INT}=sub{exit}; sleep 100" Terminating on signal SIGBREAK(21) C:\test>set PERL_SIGNALS=unsafe C:\test>perl -wle"$SIG{INT}=sub{exit}; sleep 100"

      In the first case, ^C has no effect, hence the need for ^break (SIGBREAK).

      However, the second example (with set PERL_SIGNALS=unsafe) it responds to ^C immediately.


      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.
        I know it works with unsafe signals. Never said it didn't. It's a workaround, but not the cause. The problem is that sleep is broken in Windows. It's not interrupted by signals as the documentation says it should be.