[LON-CAPA-cvs] cvs: modules /gerd/maxima lonmaxima

www lon-capa-cvs@mail.lon-capa.org
Wed, 08 Mar 2006 14:22:18 -0000


www		Wed Mar  8 09:22:18 2006 EDT

  Modified files:              
    /modules/gerd/maxima	lonmaxima 
  Log:
  At least process management now works, but Maxima behaving oddly.
  
  
Index: modules/gerd/maxima/lonmaxima
diff -u modules/gerd/maxima/lonmaxima:1.13 modules/gerd/maxima/lonmaxima:1.14
--- modules/gerd/maxima/lonmaxima:1.13	Wed Mar  8 07:57:30 2006
+++ modules/gerd/maxima/lonmaxima	Wed Mar  8 09:22:14 2006
@@ -3,7 +3,7 @@
 # The LearningOnline Network with CAPA
 # Connect to MAXIMA CAS
 #
-# $Id: lonmaxima,v 1.13 2006/03/08 12:57:30 www Exp $
+# $Id: lonmaxima,v 1.14 2006/03/08 14:22:14 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -65,6 +65,7 @@
     $SIG{CHLD} = \&REAPER;
     my $pid = wait;
     $children--;
+    &logthis("Child $pid for port or process $children{$pid} died");
     delete($usedmaximaports{$children{$pid}});
     delete($children{$pid});
 }
@@ -232,10 +233,13 @@
     for (my $i = $children; $i < $PREFORK; $i++) {
         &status('Parent process, starting child');
         my $newport;
-        foreach $newport ($STARTPORT .. $STARTPORT+$PREFORK-1) {
-            if (!defined($usedmaximaports{$newport})) { last; }
+        &logthis("Current pool: ".join(', ',keys %usedmaximaports));
+        foreach my $testport ($STARTPORT .. $STARTPORT+$PREFORK-1) {
+            if (!$usedmaximaports{$testport}) { $newport=$testport; }
+        }
+        if ($newport) {
+           &make_new_child($server,$newport);           # top up the child pool
         }
-        &make_new_child($server,$newport);           # top up the child pool
     }
 }
                                                                                 
@@ -255,8 +259,10 @@
             or die("Can't unblock SIGINT for fork: $!\n");
         $children{$pid} = $maximaport;
         $children++;
+        $usedmaximaports{$maximaport}=1;
         return;
     } else {
+        &logthis("Starting child on port $maximaport");
         # Child can *not* return from this subroutine.
         $SIG{INT} = 'DEFAULT';      # make SIGINT kill us as it did before
      
@@ -273,11 +279,12 @@
                         or die "making socket: $@\n";
         &nonblock($maximaserver);
         my $maximaselect=IO::Select->new($maximaserver);
+        sleep(2);
 
         # open MAXIMA to talk to that port
         my ($cmd_in, $cmd_out, $cmd_err);
         my $maximapid = open3($cmd_in, $cmd_out, $cmd_err, "maxima -s $maximaport");
-        $children{$maximapid} = 1;
+        $children{$maximapid} = "Maxima $maximapid port $maximaport";
         my $prompt=<$cmd_out>;
         &logthis("Maxima $maximapid: $prompt");