in reply to get() from website hangs

Thanks guys - some of the answers are over my head - but I'm giving alarm a try

Replies are listed 'Best First'.
Re^2: get() from website hangs
by FreeBeerReekingMonk (Deacon) on Sep 17, 2019 at 20:03 UTC
    I offer you this bit of code you can play with (try it with parameter 2 and then with parameter 4):

    #!/usr/bin/perl use strict; use warnings; my $delay = shift @ARGV || 1; # parameter my $timeout = 3; # seconds eval { ## Turn on timer. local $SIG{"__DIE__"}; local $SIG{CHLD}; local $SIG{ALRM} = sub { die "timed-out\n" }; alarm $timeout; my $verylongprocess = `sleep $delay`; alarm 0; # disable alarm }; die $@ if $@ eq "timed-out\n"; print "No timeout\n";

    it should cover external processes (hence, the 3 local SIG's). Not sure it works on Windows. But give it a try.

    edit 2: Yes, it works, but instead of the unix "sleep" use the Windows "timeout" command (available in W7 and W10), like so:

    my $verylongprocess = `timeout $delay`;