Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

$SIG{ALRM} and windows vista?

by 7stud (Deacon)
on Jan 04, 2010 at 01:51 UTC ( [id://815492]=perlquestion: print w/replies, xml ) Need Help??

7stud has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone tell me what is the matter with the following code? Is it a problem with the code or with Windows Vista?

use strict; use warnings; use 5.010; print 'Enter your password: '; my $password = eval { local $SIG{ALRM} = sub {die "timeout\n"}; alarm 5; return <STDIN>; }; alarm 0; if ($@ =~ /timeout/) { say "You timed out."; }

Replies are listed 'Best First'.
Re: $SIG{ALRM} and windows vista?
by ikegami (Patriarch) on Jan 04, 2010 at 03:31 UTC
    Signals are a unix thing.
      And that particular one works on windows

        readline does not emulate alarm signal interruptions.

        (I suppose it's actually the lower PerlIO layers that don't emulate them, or maybe something at an even lower level.)

        Not for me. The code doesn't time out on Windows Vista.
Re: $SIG{ALRM} and windows vista?
by BrowserUk (Patriarch) on Jan 04, 2010 at 06:16 UTC

    You're being bitten by Safe Signals. And the problem is not sourced in, nor confined to Windows.

    UPDATE: ikegami's right!

    I would have sworn that at one point after alarm was implemented on Windows and before Safe Signals were introduced, that this particular scenario worked. But I must be mixing up my memories, because it now doesn't regardless of the setting of PERL_SIGNALS=unsafe.

    Sorry for the bum steer.


    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.

      Not true.

      $ perl 815492.pl Enter your password: You timed out.

      Signals for which there is a handler will interrupt I/O operations (at the OS level) even under safe signals. readline returns (with errno = EINTR) as soon as the signal is received, allowing the signal handler to be called within milliseconds even under safe signals.

        Not on my Vista system.


        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 would have sworn that at one point after alarm was implemented on Windows and before Safe Signals were introduced

      alarm was first implemented on Windows in 5.8.0. Safe Signals were also introduced then.

      Using 5.8.0 with PERL_SIGNALS=unsafe, alarm didn't interrupt <STDIN>.

Re: $SIG{ALRM} and windows vista?
by desemondo (Hermit) on Jan 04, 2010 at 01:57 UTC
    I think you forgot to tell us what the problem is...

    Your line print 'Enter your password: '; won't appear unless you've disabled buffering or you begin reading from STDIN... If that is your problem then set $| = 1

    Updated: Thanks ikegami.
      Not so. Reading from STDIN flushes STDOUT.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://815492]
Approved by AnomalousMonk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-16 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found