SPUG: Pull out of a blocking subroutine?

Skylos skylos at gmail.com
Mon Jan 11 19:24:18 PST 2010


On Mon, Jan 11, 2010 at 6:19 PM, Christopher Howard <choward at indicium.us>wrote:

>
>
> 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?
>

BlueComm.pm line 91 looks famliar.

 91     eval
 92     {
 93       local $SIG{ALRM} = sub { die "alarm\n" };
 94       alarm 1;
 95       $nread = sysread $fh, $char, 1;
 96       alarm 0;
 97     };
 98     $rbuff .= $char;
 99   }


Listen to Mr. DeRykus.  :)

Skylos


> while(1)
> {
>    eval {
>
>        local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
>
>
>         alarm 5;
>        # $Scoop_a is my robot object
>
>        $ret =
> $Scoop_a->nxt->get_battery_level($LEGO::NXT::Constants::NXT_RET);
>         alarm 0;
>    };
>    if ($@) {
>        die unless $@ eq "alarm\n";   # propagate unexpected errors
>
>
>        # timed out
>
>
>    }
>    else {
>        # didn't
>
>
>    }
>     print "We made it through!";
>    sleep 2;
> }
>
> --
> Christopher Howard
> http://indicium.us
> http://theologia.indicium.us
> http://robots.arsc.edu
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>     POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>    MEETINGS: 3rd Tuesdays
>    WEB PAGE: http://seattleperl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20100111/cab7d7ed/attachment-0001.html>


More information about the spug-list mailing list