def mainLoop(self):
        """
        | Worker main loop:
        | - check kill file and set new status (paused, toberestartted...)
        | - update every modified command watcher for this RN
        | - remove finished commandWatchers for this RN
        | - clean "dead" commandWatchers ("dead" means a timeout val is set on the command and RUNNING time is more thant timeout val)
        | - check ping delay and resync with server if enough time elapsed
        """
        # try:
        now = time.time()

        #
        # check if the killfile is present
        #
        killfileInfo = self.getKillfileInfo()

        if killfileInfo.get('exists'):
            if not self.isPaused:
                # If RN is IDLE/RUNNING/ASSIGNED

                if killfileInfo.get('content') == -1:
                    LOGGER.warning("Flag -1 detected in killfile, killing render and pause RN")
                    self.killCommandWatchers()
                    self.pauseWorker(paused=True, killproc=True)
                    self.setKillfileInfo(None)

                if killfileInfo.get('content') == -2:
                    LOGGER.warning("Flag -2 detected in killfile, schedule restart")
                    self.killCommandWatchers()
                    self.pauseWorker(paused=True, killproc=True)
                    self.toberestarted = True
                    self.removeKillfile()

                if killfileInfo.get('content') == -3:
                    LOGGER.warning("Flag -3 detected in killfile, killing render and schedule restart")
                    self.toberestarted = True
                    self.killCommandWatchers()
                    self.pauseWorker(paused=True, killproc=True)
                    self.removeKillfile()
                else:
                    LOGGER.warning("Empty killfile, pausing worker")
                    self.pauseWorker(paused=True, killproc=False)

            else:
                # If RN is already paused

                # If killfile has a content (i.e. action is needed), exec action, else nothing to do
                if killfileInfo.get('content') == -1:
                    LOGGER.warning("Flag -1 detected in killfile, killing render")
                    self.killCommandWatchers()
                    self.pauseWorker(paused=True, killproc=True)
                    self.setKillfileInfo(None)
                if killfileInfo.get('content') == -2:
                    LOGGER.warning("Flag -2 detected in killfile, schedule restart and put empty killfile to keep pause")
                    self.toberestarted = True
                    self.killCommandWatchers()
                    self.pauseWorker(paused=True, killproc=True)
                    self.setKillfileInfo(None)
                if killfileInfo.get('content') == -3:
                    LOGGER.warning("Flag -3 detected in killfile, killing render and schedule restart")
                    self.toberestarted = True
                    self.killCommandWatchers()
                    self.pauseWorker(paused=True, killproc=True)
                    self.setKillfileInfo(None)
                # else:
                #     LOGGER.warning("Empty killfile, let worker in pause")
        else:
            # self.toberestarted = False
            # if no killfile present and worker is paused, unpause it
            if self.isPaused:
                self.pauseWorker(False, False)

        # if the worker is paused and marked to be restarted, exit program
        # Once the program has ended, the systemd service manager will automatocally restart it.
        # if self.isPaused and self.toberestarted:
        if self.toberestarted:
            # self.removeKillfile()

            LOGGER.warning("Exiting worker")
            self.framework.stop()

        #
        # Waits for any child process, non-blocking (this is necessary to clean up finished process properly)
        #
        try:
            pid, stat = os.waitpid(-1, os.WNOHANG)
            if pid:
                LOGGER.info("Cleaned process %s" % str(pid))

                # Check if pid is still in command watchers
                # In this case, clean the cmdwatcher and put cmd in error
                for commandWatcher in self.commandWatchers.values():
                    if pid == commandWatcher.processId:

                        if commandWatcher.command.status == COMMAND.CMD_RUNNING:
                            LOGGER.warning("Command was considered RUNNING: set to ERROR")
                            newStatus = COMMAND.CMD_ERROR
                        else:
                            LOGGER.warning("Keep current status: %r", commandWatcher.command.status)
                            newStatus = commandWatcher.command.status

                        LOGGER.warning("CommandWatcher killed but still referenced: %s", commandWatcher)
                        commandWatcher.finished = True

                        self.updateCompletionAndStatus(commandWatcher.commandId, commandWatcher.command.completion, newStatus, "Command termination not properly tracked.")

        except OSError:
            pass

        #
        # Send updates for every modified command watcher.
        #
        for commandWatcher in self.modifiedCommandWatchers:
            self.updateCommandWatcher(commandWatcher)

        #
        # Attempt to remove finished command watchers
        #
        for commandWatcher in self.finishedCommandWatchers:
            LOGGER.info("Removing command watcher %d (status=%r, finished=%r, modified=%r)", commandWatcher.command.id, commandWatcher.command.status, commandWatcher.finished, commandWatcher.modified)
            self.removeCommandWatcher(commandWatcher)

        #
        # Kill watchers that timeout and remove dead command watchers
        # that are not flagged as modified.
        #
        for commandWatcher in self.commandWatchers.values():
            # add the test on running state because a non running command can not timeout (Olivier Derpierre 17/11/10)
            if commandWatcher.timeOut and commandWatcher.command.status == COMMAND.CMD_RUNNING:
                responding = (now - commandWatcher.startTime) <= commandWatcher.timeOut
                if not responding:
                    # time out has been reached
                    LOGGER.warning("Timeout on command %d", commandWatcher.commandId)
                    commandWatcher.processObj.kill()
                    commandWatcher.finished = True
                    self.updateCompletionAndStatus(commandWatcher.commandId, None, COMMAND.CMD_CANCELED, None)

        # time resync
        now = time.time()

        if (now - self.lastFullSysInfoUpdate) > config.WORKER_MAX_SYSINFO_DELAY:
            # Every WORKER_MAX_SYSINFO_DELAY a request is sent to ensure a complete set of data is present on the server
            # - WORKER_MAX_SYSINFO_DELAY should be higher that WORKER_SYSINFO_DELAY
            # - WORKER_MAX_SYSINFO_DELAY could be several minutes to avoid flooding the network
            self.updateSysInfos(0)
            self.lastFullSysInfoUpdate = now

        if config.WORKER_SYSINFO_DELAY > (now - self.lastSysInfosMessageTime):
            # Every WORKER_SYSINFO_DELAY, sends a minimal set of data to the server
            self.sendSysInfosMessage()
            self.lastSysInfosMessageTime = now

        self.httpconn.close()

        # let's be CPU friendly
        time.sleep(0.05)
        # except:
        #     LOGGER.error("A problem occured : " + repr(sys.exc_info()))
dataset/ETHPy150Open mikrosimage/OpenRenderManagement/src/octopus/worker/worker.py/Worker.mainLoop/swapped operands of `>`