[aklug] Re: SPUG: Pull out of a blocking subroutine?

From: Christopher Howard <choward@indicium.us>
Date: Mon Jan 11 2010 - 17:20:02 AKST

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Christopher Howard wrote:
> Skylos wrote:
>> Sure.
>
>> http://www.sdsc.edu/~moreland/courses/IntroPerl/docs/manual/pod/perlfunc/alarm.html
>
>> eval {
>> local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
>> alarm $timeout;
>> $nread = sysread SOCKET, $buffer, $size;
>> alarm 0;
>> };
>> if ($@) {
>> die unless $@ eq "alarm\n"; # propagate unexpected errors
>> # timed out
>> }
>> else {
>> # didn't
>> }
>
>> Skylos
>
>> "If only I could get rid of hunger by rubbing my belly" - Diogenes
>
>
>> On Mon, Jan 11, 2010 at 5:27 PM, Christopher Howard <choward@indicium.us
>> <mailto:choward@indicium.us>> wrote:
>
>> Hi. I'm still working on integrating LEGO::NXT into my project. Problem
>> I've hit though is that apparently there are no actual functions for
>> checking communication status with the robot.
>
>> There is other function I thought I could use to detect (implicitly) if
>> communication is still established. Problem is that they are /all/
>> blocking. Documentation basically says that the author hasn't got around
>> to making non-blocking functions yet, and I don't really have time to
>> reprogram his module myself.
>
>> So, my perverted, evil question: Is there some hackish way to pull out
>> of a blocking subroutine? Say, if it has returned after three seconds or
>> something like that?
>
>> --
>> Christopher Howard
>> http://indicium.us
>> http://theologia.indicium.us
>> http://robots.arsc.edu
>
>
>> _____________________________________________________________
>> Seattle Perl Users Group Mailing List
>> POST TO: spug-list@pm.org <mailto:spug-list@pm.org>
>> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>> MEETINGS: 3rd Tuesdays
>> WEB PAGE: http://seattleperl.org/
>
>
>
> 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?
>
> 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;
> }
>

Sorry, wrong list.

- --
Christopher Howard
http://indicium.us
http://theologia.indicium.us
http://robots.arsc.edu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAktL3FEACgkQQ5FLNdi0BcWMnACfdEapZQgoR/WPPX17UtPb5Vqd
FVEAn1JT7X7NEfdQoTOPdFvoPfGpBmC9
=qyBw
-----END PGP SIGNATURE-----
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Mon Jan 11 17:22:04 2010

This archive was generated by hypermail 2.1.8 : Mon Jan 11 2010 - 17:22:04 AKST