At 11:02 AM 8/16/01 -0500, Tyler Longren wrote:
>Hello list,
>
>How should I go about setting a timeout for a section of code?  I've
>written some code to do a whois on a few hosts.  Sometimes, it stay's on
>one host for a few minutes, trying to connect to the whois server.
>
>Here's the code:
>foreach my $h(@list) {
>         my $result = `whois $h`;
>}
>
>Is there any way to add, say a 30 second timeout to this?  I've looked at
>the man pages for whois, and there doesn't appear to be any way to set a
>timeout in the whois command.

Try this:

$ perldoc -q timeout
Found in /usr/lib/perl5/5.6.1/pod/perlfaq8.pod
        How do I timeout a slow event?

        Use the alarm() function, probably in conjunction with a
        signal handler, as documented in the Signals entry in the
        perlipc manpage and the section on ``Signals'' in the
        Camel.  You may instead use the more flexible
        Sys::AlarmCall module available from CPAN.


--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

  • timeout Tyler Longren
    • Peter Scott

Reply via email to