Skip to content

Instantly share code, notes, and snippets.

@takus
Created March 26, 2013 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takus/5243221 to your computer and use it in GitHub Desktop.
Save takus/5243221 to your computer and use it in GitHub Desktop.
Time::HiRes::alarm(0); しないと意図しない箇所で die する例
#!/usr/bin/env perl
use strict;
use warnings;
use POSIX qw(SIGALRM);
use Time::HiRes;
print "begin\n";
eval {
POSIX::sigaction(
SIGALRM, POSIX::SigAction->new(sub { die "timeout\n" })
) or die "can't set SIGALRM handler: $!\n";
Time::HiRes::alarm(10);
sleep(8);
};
if ($@) {
print $@;
}
sleep(4);
print "end\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment