Ignore:
Timestamp:
2011-12-01T12:33:53+13:00 (12 years ago)
Author:
jmt12
Message:

Added the ability for the server to detect if it's calling process has gone away, and shutdown if so. This test is run every 5 seconds or so

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/bin/script/GDBMServer.pl

    r24679 r24847  
    297297    $server = SocketsSwimmingThreadPoolServer->new(host=>$host,
    298298                                                   port=>$port,
     299                                                   main_cb => \&exitCheck,
    299300                                                   processor_cb => \&process);
    300301
     
    351352}
    352353exit(0);
     354
     355# @function exitCheck
     356# A callback function, called every 5 seconds (default) by the socket server,
     357# to see whether the parent process (by pid) is actually still running. This
     358# will cover the case where the parent process (import.pl or build.pl) dies
     359# without properly asking the server to shutdown.
     360sub exitCheck
     361{
     362  my $counter = shift @_;
     363  # note: kill, when passed a first argument of 0, checks whether it's possible
     364  # to send a signal to the pid given as the second argument, and returns true
     365  # if it is. Thus it provides a means to determine if the parent process is
     366  # still running (and hence can be signalled) In newer versions of Perl
     367  # (5.8.9) it should even work cross-platform.
     368  if (!kill(0, $parent_pid))
     369  {
     370    print " * Parent processs gone away... forcing server shutdown\n";
     371    $server->stop;
     372    if ($debug)
     373    {
     374      lock($debug_log);
     375      $|++;
     376      print "[" . time() . "|MAIN] Parent process gone away... forcing server shutdown.\n\n";
     377      $|--;
     378    }
     379  }
     380}
    353381
    354382# /** @function process
Note: See TracChangeset for help on using the changeset viewer.