You have to remember that Win32 does not have signals as a native concept. Perl's support for them is simulated and limited, and is actually implemented via the process message queue. This is the code that implements the signal emulations from win32.c:

void sig_terminate(pTHX_ int sig) { Perl_warn(aTHX_ "Terminating on signal SIG%s(%d)\n",PL_sig_name[si +g], sig); /* exit() seems to be safe, my_exit() or die() is a problem in ^C +thread */ exit(sig); } DllExport int win32_async_check(pTHX) { MSG msg; int ours = 1; /* Passing PeekMessage -1 as HWND (2nd arg) only get PostThreadMes +sage() messages * and ignores window messages - should co-exist better with windo +ws apps e.g. Tk */ while (PeekMessage(&msg, (HWND)-1, 0, 0, PM_REMOVE|PM_NOYIELD)) { int sig; switch(msg.message) { #if 0 /* Perhaps some other messages could map to signals ? ... */ case WM_CLOSE: case WM_QUIT: /* Treat WM_QUIT like SIGHUP? */ sig = SIGHUP; goto Raise; break; #endif /* We use WM_USER to fake kill() with other signals */ case WM_USER: { sig = msg.wParam; Raise: if (do_raise(aTHX_ sig)) { sig_terminate(aTHX_ sig); } break; } case WM_TIMER: { /* alarm() is a one-shot but SetTimer() repeats so kill it + */ if (w32_timerid && w32_timerid==msg.wParam) { KillTimer(NULL,w32_timerid); w32_timerid=0; } else goto FallThrough; /* Now fake a call to signal handler */ if (do_raise(aTHX_ 14)) { sig_terminate(aTHX_ 14); } break; } /* Otherwise do normal Win32 thing - in case it is useful */ default: FallThrough: TranslateMessage(&msg); DispatchMessage(&msg); ours = 0; break; } } w32_poll_count = 0; /* Above or other stuff may have set a signal flag */ if (PL_sig_pending) { despatch_signals(); } return ours; }

Setting the environment variable PERL_SIGNALS=unsafe allows ^C to interupt sleep. Without it, the signal handler doesn't get invoked until the sleep is over.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: win32, ctrl-c, sleep, and signals by BrowserUk
in thread win32, ctrl-c, sleep, and signals by SirBones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.