Thank you very much for your reply! As I replied to pryrt, I also now see the different behavior on Windows.

During all my earlier testing I was actually reminded of an interaction between sleep and alarm: "You probably cannot mix alarm and sleep calls, because sleep is often implemented using alarm." Note how the second and third times are the same:

$ perl -wMstrict -e '$SIG{ALRM}=sub{print time." Timeout"};print time. +" Before\n";alarm 2;sleep 10;print time." After\n"' 1532118865 Before 1532118867 Timeout1532118867 After

But if you emulate sleep with polling, you see the same buffering issue as in the other cases - here, the second line of output isn't printed until after the 10 seconds are up:

$ perl -wMstrict -e '$SIG{ALRM}=sub{print time." Timeout"};print time. +" Before\n";alarm 2;$a=time+10;1 while time<$a;print time." After\n"' 1532118963 Before 1532118965 Timeout1532118973 After

Update: And on Windows:

> perl -wMstrict -e "$SIG{ALRM}=sub{print time.qq{ Timeout}};print tim +e.qq{ Before\n};alarm 2;sleep 10;print time.qq{ After\n}" 1532119202 Before 1532119204 Timeout1532119212 After > perl -wMstrict -e "$SIG{ALRM}=sub{print time.qq{ Timeout}};print tim +e.qq{ Before\n};alarm 2;$a=time+10;1 while time<$a;print time.qq{ Aft +er\n}" 1532119272 Before 1532119274 Timeout1532119282 After

Where each second line of output isn't printed until after 10 seconds.


In reply to Re^15: Print inside SIGNALS (updated) by haukex
in thread Print inside SIGNALS by pedrete

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.