gnome-games r7623 - in trunk/glchess: . src/lib



Author: rancell
Date: Sun Apr 13 09:11:37 2008
New Revision: 7623
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7623&view=rev

Log:
Check PID returned on SIGCHLD (Bug #527686)
Add missing gettext call for the Application Log viewer. (Jordi Mallach  <jordi sindominio net>)



Modified:
   trunk/glchess/ChangeLog
   trunk/glchess/src/lib/ai.py
   trunk/glchess/src/lib/main.py

Modified: trunk/glchess/src/lib/ai.py
==============================================================================
--- trunk/glchess/src/lib/ai.py	(original)
+++ trunk/glchess/src/lib/ai.py	Sun Apr 13 09:11:37 2008
@@ -230,29 +230,31 @@
         self.__fromEngineFd = fromManagerOutput
         
         # Catch if the child dies
+        self.__pid = None
         def cDied(sig, stackFrame):
             try:
-                os.waitpid(-1, os.WNOHANG)
+                (pid, status) = os.waitpid(-1, os.WNOHANG)
             except OSError:
                 pass
-           
-            # If unexpected then AI has died
-            if self.__fromEngineFd != None:
-                print 'Monitor died'
-                self.die()
+            else:
+                # If unexpected then AI has died
+                if pid == self.__pid and self.__fromEngineFd != None:
+                    print 'Monitor died'
+                    self._die()
         signal.signal(signal.SIGCHLD, cDied)
 
         # Fork off a child process to manage the engine
-        if os.fork() == 0:
+        self.__pid = os.fork()
+        if self.__pid == 0:
             os.close(toManagerInput)
             os.close(fromManagerOutput)
             self._runMonitor(fromManagerInput, toManagerOutput)
             os.close(toManagerOutput)
             os.close(fromManagerInput)
             os._exit(0)
-        else:
-            os.close(toManagerOutput)
-            os.close(fromManagerInput)
+
+        os.close(toManagerOutput)
+        os.close(fromManagerInput)
 
         if profile.protocol == CECP:
             self.connection = CECPConnection(self)
@@ -310,11 +312,11 @@
                 data = os.read(self.__fromEngineFd, 256)
             except OSError, e:
                 print 'Error reading from chess engine: ' + str(e)
-                self.die()
+                self._die()
                 return False
             if len(data) == 0:
                 print 'Engine has died'
-                self.die()
+                self._die()
                 return False
             self.connection.registerIncomingData(data)
 
@@ -337,8 +339,9 @@
         
         # Send quit
         try:
-            os.write(fd, '\nquit\n') # FIXME: CECP specific
-        except:
+            if fd is not None:
+                os.write(fd, '\nquit\n') # FIXME: CECP specific
+        except OSError:
             return
 
     # Extended methods
@@ -370,6 +373,10 @@
     def onGameEnded(self, game):
         """Called by game.ChessPlayer"""
         self.quit()
+        
+    def _die(self):
+        self.quit()
+        self.die()
 
     def _runEngine(self, toEngineFd, fromEngineFd):
         # Make the engine low priority for CPU usage
@@ -420,7 +427,7 @@
                  toEngineInput, fromEngineOutput)
                  
         try:
-            while True:                
+            while True:
                 # Wait for data
                 (rfds, _, xfds) = select.select(inputPipes, [], pipes, None)
                 

Modified: trunk/glchess/src/lib/main.py
==============================================================================
--- trunk/glchess/src/lib/main.py	(original)
+++ trunk/glchess/src/lib/main.py	Sun Apr 13 09:11:37 2008
@@ -428,7 +428,7 @@
         
         self.history = history.GameHistory()
         
-        self.logger = self.ui.controller.addLogWindow('Application Log', '', '')
+        self.logger = self.ui.controller.addLogWindow(_('Application Log'), '', '')
 
     def addAIProfile(self, profile):
         """Add a new AI profile into glChess.
@@ -455,8 +455,10 @@
     def watchAIPlayer(self, p):
         """
         """
-        self.ioHandlers[p.fileno()] = p
-        self.ui.controller.watchFileDescriptor(p.fileno())
+        fd = p.fileno()
+        if fd is not None:
+            self.ioHandlers[fd] = p
+            self.ui.controller.watchFileDescriptor(fd)
 
     def unwatchAIPlayer(self, p):
         """



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]