def addCommandWatcher(self, command):
        newCommandWatcher = self.CommandWatcher()
        newCommandWatcher.commandId = command.id

        commandId = command.id

        from octopus.commandwatcher import commandwatcher
        logdir = os.path.join(settings.LOGDIR, command.relativePathToLogDir)
        outputFile = os.path.join(logdir, '%d.log' % (commandId))
        commandWatcherLogFile = outputFile

        # Fix PB PRECOMPILATION (notamment quand on exec en local, il peut y avoir un mix)
        # scriptFile = commandwatcher.__file__
        scriptFile = commandwatcher.__file__[:-1] if commandwatcher.__file__.endswith(".pyc") else commandwatcher.__file__
        LOGGER.info("Use commandWatcher script file: %r", scriptFile)

        workerPort = self.framework.webService.port

        pidFile = os.path.join(self.PID_DIR, "cw%s.pid" % newCommandWatcher.commandId)

        # create the logdir if it does not exist
        if not os.path.exists(logdir):
            try:
                os.makedirs(logdir, 0777)
            except OSError, e:
                import errno
                err = e.args[0]
                if err != errno.EEXIST:
                    raise
        logFile = file(outputFile, "w")

        d = os.path.dirname(pidFile)
        if not os.path.exists(d):
            try:
                os.makedirs(d, 0777)
            except OSError, e:
                import errno
                err = e.args[0]
                if err != errno.EEXIST:
                    raise

        # Add several info in env to be used by the runner
        command.environment["PULI_COMMAND_ID"] = command.id
        command.environment["PULI_RUNNER_PACKAGES"] = command.runnerPackages
        command.environment["PULI_TASK_NAME"] = command.taskName
        command.environment["PULI_TASK_ID"] = command.relativePathToLogDir
        command.environment["PULI_LOG"] = outputFile

        # LOGGER.debug("command.runnerPackages = %s" % command.runnerPackages)
        # LOGGER.debug("command.watcherPackages = %s" % command.watcherPackages)
        if 'REZ_USED_RESOLVE' in os.environ:
            pythonExec = "python"
            runnerPackages = command.runnerPackages if command.runnerPackages != '' else 'undefined'
        else:
            pythonExec = sys.executable
            runnerPackages = "undefined"

        args = [
            pythonExec,
            "-u",
            scriptFile,
            commandWatcherLogFile,
            str(settings.DISPATCHER_ADDRESS + ":" + str(settings.DISPATCHER_PORT)),
            str(workerPort),
            str(command.id),
            command.runner,
            command.validationExpression,
            runnerPackages,
            json.dumps(command.arguments)
        ]

        try:
            # Starts a new process (via CommandWatcher script) with current command info and environment.
            # The command environment is derived from the current os.env
            if 'REZ_USED_RESOLVE' in os.environ:
                LOGGER.warning("Current worker managed with rez, command watcher packages are: %s" % command.watcherPackages)
                watcherProcess = spawnRezManagedCommandWatcher(pidFile, logFile, args, command.watcherPackages, command.environment)
            else:
                LOGGER.warning("Current worker is not rez-managed (undefined REZ_USED_RESOLVE in env)")
                watcherProcess = spawnCommandWatcher(pidFile, logFile, args, command.environment)

            newCommandWatcher.processObj = watcherProcess
            newCommandWatcher.startTime = time.time()
            newCommandWatcher.timeOut = None
            newCommandWatcher.command = command
            newCommandWatcher.processId = watcherProcess.pid

            self.commandWatchers[command.id] = newCommandWatcher
            self.status = rendernode.RN_WORKING

            LOGGER.info("Started command %d", command.id)
        except Exception, e:
            LOGGER.error("Error spawning command watcher %r", e)
            raise e
dataset/ETHPy150Open mikrosimage/OpenRenderManagement/src/octopus/worker/worker.py/Worker.addCommandWatcher/original