http://qs321.pair.com?node_id=649115

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

eval { local $SIG{ALRM} = sub { die "Unable to initiate Zip4 connection"; + }; alarm(1); $zip4 = new Win32::DDE::Client('ZP4', 'Addresses'); $SIG{ALRM}->() if $zip4->Error; alarm(0); }; die $@ if $@;
This works just fine when I replace the $zip4 parts of the code with something else, like say sleep(10). However, if the ZP4 application doesn't happen to be running already and ready for connections, it just sits there and hangs rather than dying after 1 second like it's supposed to. Why?

Replies are listed 'Best First'.
Re: $SIG{ALRM} timeout and Win32::DDE::Client hangs?
by BrowserUk (Patriarch) on Nov 06, 2007 at 01:36 UTC

    See the POD:

    Timeout (NEWVALUE)

    If NEWVALUE is present, set the timeout value (in milliseconds) used for DDE operations; return the old value.

    The timeout value is initially set to $Win32::DDE::Client::Timeout when the object is constructed. $Win32::DDE::Client::Timeout is set to 1000 when the module is loaded.


    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.
Re: $SIG{ALRM} timeout and Win32::DDE::Client hangs?
by erroneousBollock (Curate) on Nov 06, 2007 at 01:00 UTC
    Signals (in perl) are a hack on Win32, you can't expect them to be delivered to (and understood by) non-perl Win32 software like the "ZP4" application (whatever that is).

    -David