in reply to Re^14: Print inside SIGNALS
in thread Print inside SIGNALS
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^16: Print inside SIGNALS (updated)
by Veltro (Hermit) on Jul 20, 2018 at 21:26 UTC |