in reply to Re^13: Print inside SIGNALS
in thread Print inside SIGNALS

I don't care much about what ikagami said exactly

That's a strange thing to say when that's all this sub-thread is about. Please re-read the thread starting from here.

ctrl-c pressed < 2 seconds

No, that's exactly the thing I have an issue with: I certainly have a dense moment now and then, but I'm not dumb enough to set an alarm for two seconds upon which something is to be printed, kill the program before the two seconds is up, and then use this as my evidence that nothing was printed. And I'm going to take special care when I'm pointing out a potential mistake to a Monk whose technical knowledge is much deeper than mine and who is almost always right in his posts.

And it should be obvious to anyone that I didn't hit Ctrl-C within the first two seconds if they had actually run my first two one-liners (again, assuming their system behaves the same as mine). Which is why I posted them in the first place!

but you did kill the program ... As far as I'm concerned that is the reason why your example does not print anything.

Then you are making this same incorrect (and insulting) assumption that ikegami did. Did you try out my most recent one-liner that has nothing to do with SIGINT?

STDOUT ... matters everything

No, it does not.

$ perl -e '$x=time; $SIG{ALRM}=sub{$y=time; close STDIN}; alarm 2; <>; print STDERR $y-$x," ",time-$x,"\n"' 2 2

Just to make it clear: This shows how <> is interrupted by $SIG{ALRM}, without STDOUT being involved at all. Which is why I think that the first snippet posted by pedrete here is just suffering from buffering (but I'm always willing to be proven wrong).

$SIG{'INT'} = sub { exit(0) } ;

This misses the point, because of course the output buffers get flushed on exit. With buffering issues, the question is not whether something gets printed, but when. And perhaps you overlooked that the OP confirmed that it was a buffering issue all along.

I've said all I can say until someone shows some actual evidence to the contrary.

Replies are listed 'Best First'.
Re^15: Print inside SIGNALS
by Veltro (Hermit) on Jul 19, 2018 at 21:46 UTC

    In this part:

    (1. ctrl-c pressed < 2 seconds 2. ctrl-c pressed > 2 seconds)

    It was me who pressed ctrl-c within 2 seconds to show the output of the program when I would. I have never said that you did.

    So fine, I feel that you that you are twisting my words and I guess this is the way you want to go, so let this be the last time I will bring up an issue with you. I've never tried to insult you. I guess that's what you get speaking out to 'popular' monks. Disregards of whatever I tried to bring up.

      You are right that my post is a bit harsh. I let my annoyance with this whole sub-thread affect my reply to you too much, and I apologize.

      I have re-read your posts (I just haven't had a chance to try out your code in the "edit 2" because it's getting late). If I understand correctly, the main point you were making is that an unhandled SIGINT means that Perl doesn't get to flush its buffers, while a clean exit does. You are of course right in that, as well as in your point that STDERR is unbuffered by default. If I'm missing anything else, please feel free to point it out.

      I would ask this of you though: Assume for a moment that going into this discussion, I already knew the behavior of SIGINT, STDOUT, and STDERR. If you keep that in mind when looking over the thread, perhaps you can see my point of view of how this thread went, and maybe also why I disagreed with you (in the context of this thread) that "both of you are correct".

        If I understand correctly, the main point you were making is that an unhandled SIGINT means that Perl doesn't get to flush its buffers

        For the fifth time, no. That's what *you* keep saying, and it's wrong.

        Because you pressed Ctrl-C, the signal handler didn't get called at all. There never was a print, so there wasn't anything to flush.

Re^15: Print inside SIGNALS
by ikegami (Patriarch) on Jul 20, 2018 at 18:48 UTC

    And it should be obvious to anyone that I didn't hit Ctrl-C within the first two seconds

    duh. I never claimed you killed it within the first two seconds. I said you killed it before <> returned, and thus before the signal handler was called.

    Then you are making this same incorrect (and insulting) assumption that ikegami did.

    You tried to disprove my claim that the signal handler does get called once <> returns by killing the process before it returns. So you failed. But now, you're compounding that by making stupid assumptions. Stop, and think.

      Responding to your ninja edit...

      You tried to disprove my claim that the signal handler does get called once <> returns by killing the process before it returns. So you failed. But now, you're compounding that by making stupid assumptions. Stop, and think.

      I understand there was some ambiguity in the very first code snippet I showed, which is why I also showed further examples further down in the thread, which you clearly haven't tried to run yourself on a Linux system. Until you do, and actually respond to the points I raised, I'm done with this nonsense. Update: Sorry. Please see my reply here.

        Until you do, and actually respond to the points I raised, I'm done with this nonsense.

        I responded to all the points you raised in replies to me.

        Sorry. Please see my reply here.

        Oh wow. That program contradicts what I said. I stand corrected.

        That's so weird. Perl signals can be checked explicitly by ops and XS functions if they so desire, but it's hardly done for obvious reasons. That means they specifically added a signal check in the middle of <>. I did not expect that!

      I said you killed it before <> returned, and thus before the signal handler was called.

      Explain the behavior of the one-liners I provided in this thread so far, otherwise I have to just assume you are trolling me. Update: Sorry. Please see my reply here.