Working with timeouts
    Ask Bjørn Hansen 
    ask at develooper.com
       
    Tue Nov 27 22:01:31 UTC 2007
    
    
  
On Nov 27, 2007, at 1:52 PM, Sam Tregar wrote:
> How are you doing it exactly - alarm() or something fancier?  Care  
> to share your code?
Yeah, just with alarm.  Variations of:
     my $result = eval {
         local $SIG{ALRM} = sub { die "timeout" };
         alarm $timeout + 2;
         my $result = $gclient->do_task($func_name, freeze($args));
         alarm 0;
         return $result;
     };
     alarm 0;
     die ERROR_FOOBAR->with_description("System error: No data  
returned: $@")
             if ($@ or !($result and $$result));
The double "alarm 0" is to make sure the alarm gets reset before we  
exit the eval and in case of error.
IIRC the $timeout+2 here is because we have the worker do timeouts too  
(the worker in this case is doing a sometimes large job against  
another server with an obscure protocol), so we have the worker do a  
timeout on that too and sometimes it can return a more meaningful  
result than we get when the client does the timeout.
   - ask
-- 
http://develooper.com/ - http://askask.com/
    
    
More information about the Gearman
mailing list