def executeCommand(self, command): logger.debug('Executing command: ' + command.summary()) self.game.permission.acquire() self.validateRegisteredCommand(command) command.process(self.game) self.game.notifyExecutedCommand(command) self.game.permission.release() self.executedCommands.append(command) logger.info('> ' + command.summary()) if isinstance(command, PlayerCommand): logger.info(command.player.context.summary())
try: self.thread = threading2.KThread(target=self.run, name='Thread-Game') self.thread.daemon = True self.thread.start() self.thread.joinWithTimeout(self.configurations.timeForGame) if self.thread.isExpired(): raise errors.TimeoutGameError() except Exception, e: logger.debug('Error in game: ' + e.message) self.reportCollector.exception = e raise e finally: endTime = time.clock() self.reportCollector.durationTime = (endTime - startTime) logger.debug('End game') logger.info('Winners: ' + ' '.join(winner.name for winner in self.winners())) def stop(self): logger.debug('Game stopped') self.thread.kill() # Template Method def run(self): logger.debug('Running...') self.commandsManager.start() self.commandsManager.addCommand(self.startCommand) self.play() self.reportCollector.winners = self.winners() self.commandsManager.addCommand(self.endCommand) self.commandsManager.stop() logger.debug('ok')