gnome-games r7991 - trunk/glchess/src/lib
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r7991 - trunk/glchess/src/lib
- Date: Thu, 9 Oct 2008 04:33:54 +0000 (UTC)
Author: rancell
Date: Thu Oct 9 04:33:54 2008
New Revision: 7991
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7991&view=rev
Log:
Handle fork() errors in AI processes (Bug #530425)
Modified:
trunk/glchess/src/lib/ai.py
Modified: trunk/glchess/src/lib/ai.py
==============================================================================
--- trunk/glchess/src/lib/ai.py (original)
+++ trunk/glchess/src/lib/ai.py Thu Oct 9 04:33:54 2008
@@ -239,33 +239,43 @@
self.__fromEngineFd = fromManagerOutput
# Fork off a child process to manage the engine
- self.__pid = os.fork()
- if self.__pid == 0:
+ try:
+ self.__pid = os.fork()
+ except OSError, e:
+ print 'Monitor failed to fork: %s' % e.message
os.close(toManagerInput)
- os.close(fromManagerOutput)
- self._runMonitor(fromManagerInput, toManagerOutput)
os.close(toManagerOutput)
os.close(fromManagerInput)
- os._exit(0)
+ os.close(fromManagerOutput)
+ self.__toEngineFd = None
+ self.__fromEngineFd = None
+ else:
+ if self.__pid == 0:
+ os.close(toManagerInput)
+ os.close(fromManagerOutput)
+ self._runMonitor(fromManagerInput, toManagerOutput)
+ os.close(toManagerOutput)
+ os.close(fromManagerInput)
+ os._exit(0)
- os.close(toManagerOutput)
- os.close(fromManagerInput)
+ os.close(toManagerOutput)
+ os.close(fromManagerInput)
- if profile.protocol == CECP:
- self.connection = CECPConnection(self)
- elif profile.protocol == UCI:
- self.connection = UCIConnection(self)
- else:
- assert(False)
+ if profile.protocol == CECP:
+ self.connection = CECPConnection(self)
+ elif profile.protocol == UCI:
+ self.connection = UCIConnection(self)
+ else:
+ assert(False)
- self.connection.start()
- self.connection.startGame()
- try:
- level = self.__profile.levels[self.__level]
- except KeyError:
- self.connection.configure()
- else:
- self.connection.configure(level.options)
+ self.connection.start()
+ self.connection.startGame()
+ try:
+ level = self.__profile.levels[self.__level]
+ except KeyError:
+ self.connection.configure()
+ else:
+ self.connection.configure(level.options)
# Methods to extend
@@ -343,12 +353,17 @@
def onPlayerMoved(self, player, move):
"""Called by game.ChessPlayer"""
+ if self.__toEngineFd == None:
+ return
isSelf = player is self and self.moving
self.moving = False
self.connection.reportMove(move.canMove, isSelf)
def readyToMove(self):
"""Called by game.ChessPlayer"""
+ if self.__toEngineFd == None:
+ self.die()
+ return
game = self.getGame()
whiteTime = game.getWhite().getRemainingTime()
blackTime = game.getBlack().getRemainingTime()
@@ -404,7 +419,11 @@
(fromEngineOutput, fromEngineInput) = os.pipe()
# Fork and execute the child
- enginePID = os.fork()
+ try:
+ enginePID = os.fork()
+ except OSError, e:
+ print 'Monitor failed to fork: %s' % e.message
+ os._exit(1);
if enginePID == 0:
os.close(toApplicationFd)
os.close(fromApplicationFd)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]