SPUG: Pull out of a blocking subroutine?
Charles DeRykus
derykus at gmail.com
Mon Jan 11 19:18:16 PST 2010
> > This sounds like exactly what I need, but it doesn't seem to
> be working.
> > It still freezes at the call to Does it make any difference that I am
>
> not making a simple system call, but instead a call to a function in a
> > module?
>
perlipc's POSIX workaround can help if the function has a
networking call with its own timeout which interferes with the
timeout you've set. Here's a couple of changes to demo the
fix although perlipc warns this will bypass safe signals:
use POSIX qw(SIGALRM); # <---
> while(1)
> > {
> > eval {
> >
> > # local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
>
POSIX::sigaction(SIGALRM, # <---
POSIX::SigAction->new(sub { die "alarm"; } ) )
or die "Error setting SIGALRM handler: $!\n";
> alarm 5;
> # $Scoop_a is my robot object
> $ret =
> $Scoop_a->nxt->get_battery_level(
> $LEGO::NXT::Constants:: NXT_RET);
> alarm 0;
>};
> ...
Of course,nothing helps if the function does this:
local $SIG{ALRM} = 'IGNORE';
--
Charles DeRykus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20100111/4ecaadbf/attachment.html>
More information about the spug-list
mailing list