[Melbourne-pm] Timer::HiRes and alarms? (Was: AI Contest)

Toby Corkindale toby.corkindale at strategicdata.com.au
Thu Nov 4 21:31:20 PDT 2010


On 05/11/10 14:20, Nathan Bailey wrote:
> So the contest requires each turn to be submitted within one second. So
> logically, one would endeavour to use Time::HiRes and an alarm to make
> sure that you submit a turn no matter what happens, but I seem to have
> the syntax for Timer::HiRes/alarm's wrong. I would expect that this:
>     eval {
>        local $SIG{ALRM} = sub { warn "Alarm initiated\n"; print "go\n"; };
>        setitimer(ITIMER_REAL, 0.9);
>        while(1) { ; }
>     };
>     if ($@) {
>        warn "Alarm happened?";
>        die $@;
>     }
> would:
>   a) initiate an alarm event 900ms after the setitimer statement is run
>   b) submit an end turn command ('go') to stdout/the server = successful
> turn completion
>   b) make the $@ block run when it does time out (as it will, with our
> while(1))
>
> So the above code should successfully submit empty turns every turn.
>
> 'Alarm initiated' does get printed, but 'go' doesn't seem to go to the
> server. Am I using alarm wrong or is this a contest-specific issue?

Have you made sure to enable autoflush on stdout?

Does the code work if you run the code locally with the tcp server?
(ie. is it related to the sandbox the java code runs your bot in? I 
wouldn't be too surprised if it was blocking signals.)


More information about the Melbourne-pm mailing list