reading box configurations and starting timers to start/monitor/kill processes
967641
def start(self, *_):
        
        try:
            box_configurations = self.bc_dao.run_query(QUERY_PROCESSES_FOR_BOX_ID(self.box_id))

            for box_config in box_configurations:
                handler = RepeatTimer(TRIGGER_INTERVAL, self.manage_process, args=[box_config.process_name])
                self.thread_handlers[box_config.process_name] = handler
                handler.start()
                self.logger.info('Started Supervisor Thread for {0}, triggering every {1} seconds'
                                 .format(box_config.process_name, TRIGGER_INTERVAL))
        except LookupError as e:
            self.logger.error('Supervisor failed to start because of: {0}'.format(e))
246596
def cli(*, worker_settings, burst, check, watch, verbose):
    
    sys.path.append(os.getcwd())
    worker_settings = import_string(worker_settings)
    logging.config.dictConfig(default_log_config(verbose))

    if check:
        exit(check_health(worker_settings))
    else:
        kwargs = {} if burst is None else {'burst': burst}
        if watch:
            loop = asyncio.get_event_loop()
            loop.run_until_complete(watch_reload(watch, worker_settings, loop))
        else:
            run_worker(worker_settings, **kwargs)
43893
function spawnWatcher() {
  var subprocess = spawn(process.argv[0], ['prebuild.js', '--watcher'], {detached: true, stdio: 'ignore'})
  subprocess.unref()
}
116290
def main(self):
        
        try:
            # Start the daemon
            if not self.verify_only and not self.do_daemon_init_and_start():
                self.exit_on_error(message="Daemon initialization error", exit_code=3)

            if self.verify_only:
                self.setup_alignak_logger()

            # Load monitoring configuration files
            self.load_monitoring_config_file()

            # Set my own process title
            self.set_proctitle(self.name)

            # Now we can start our "external" modules (if any):
            self.modules_manager.start_external_instances()

            # Now we can load the retention data
            self.hook_point('load_retention')

            # And go for the main loop
            while True:
                self.do_main_loop()
                logger.info("Exited from the main loop.")

                # Exiting the main loop because of a configuration reload
                if not self.need_config_reload:
                    # If no configuration reload is required, stop the arbiter daemon
                    self.request_stop()
                else:
                    # Loop if a configuration reload is raised while
                    # still reloading the configuration
                    while self.need_config_reload:
                        # Clear the former configuration
                        self.need_config_reload = False
                        self.link_to_myself = None
                        self.conf = Config()
                        # Load monitoring configuration files
                        _ts = time.time()
                        logger.warning('--- Reloading configuration...')
                        self.load_monitoring_config_file()
                        duration = int(time.time() - _ts)
                        self.add(make_monitoring_log('info', 'CONFIGURATION RELOAD;%d' % duration))
                        logger.warning('--- Configuration reloaded, %d seconds', duration)

                        # Make a pause to let our satellites get ready...
                        pause = max(1, self.conf.daemons_new_conf_timeout)
                        if pause:
                            logger.info("Pausing %.2f seconds...", pause)
                            time.sleep(pause)

        except Exception as exp:  # pragma: no cover, this should never happen indeed ;)
            # Only a master arbiter can stop the daemons
            if self.is_master:
                # Stop the daemons
                self.daemons_stop(timeout=self.conf.daemons_stop_timeout)
            self.exit_on_exception(raised_exception=exp)
            raise
271729
def _main_loop(self):
        '''
        
        '''
        self.logger.debug("Running main loop")
        old_time = 0
        while True:
            for plugin_key in self.plugins_dict:
                obj = self.plugins_dict[plugin_key]
                self._process_plugin(obj)

            if self.settings['STATS_DUMP'] != 0:
                new_time = int(old_div(time.time(), self.settings['STATS_DUMP']))
                # only log every X seconds
                if new_time != old_time:
                    self._dump_stats()

                    if self.settings['STATS_DUMP_CRAWL']:
                        self._dump_crawl_stats()

                    if self.settings['STATS_DUMP_QUEUE']:
                        self._dump_queue_stats()

                    old_time = new_time
            self._report_self()
            time.sleep(self.settings['SLEEP_TIME'])
202638
def start_processing_handler(self, event):
        """"""
        results_path = os.path.join(self.configuration['results_folder'],
                                    "filesystem.json")
        self.logger.debug("Event %s: start comparing %s with %s.",
                          event, self.checkpoints[0], self.checkpoints[1])

        results = compare_disks(self.checkpoints[0], self.checkpoints[1],
                                self.configuration)

        with open(results_path, 'w') as results_file:
            json.dump(results, results_file)

        self.processing_done.set()
1014359
def parse_timers(self):
        
        filenames = list(filter(os.path.exists, [task.output_file.path for task in self]))

        parser = AbinitTimerParser()
        parser.parse(filenames)

        return parser
719948
function() {
        if (process.platform !== 'darwin') {
            return;
        }

        // top is running in logging mode, spewing process info to stdout every second.
        this._topConsole = child_process.spawn('/usr/bin/top', ['-l', '0', '-stats', 'pid,cpu,mem,command']);
        this._topConsole.stdout.on('data', _.bind(function(stdout) {
            var id = $$persistence.processId();
            if (!id) {
                return;
            }

            // Find the line with the process id that matches what we're watching.
            stdout = stdout.toString();
            var lines = stdout.split('\n');
            var line = lines.filter(function(line) {
                return line.indexOf(id) === 0;
            })[0];
            if (!line) {
                return;
            }
            var parts = line.split(/\s+/g);

            // Add to the CPU history.
            var cpu = parseFloat(parts[1]);
            this._cpuFrame(cpu);

            // Add to the memory history.
            var memory = parts[2];
            var unit = 1;
            if (memory.indexOf('K') !== -1) {
                unit = 1024;
            } else if (memory.indexOf('M') !== -1) {
                unit = 1024 * 1024;
            } else if (memory.indexOf('G') !== -1) {
                unit = 1024 * 1024 * 1024;
            }
            memory = memory.replace(/[\D]/g, '');
            memory = parseInt(memory) * unit;
            this._memoryFrame(memory);

        }, this));
    }
359435
protected void startJvmMonitorProcess() {
    if (ServerConfiguration.getBoolean(PropertyKey.MASTER_JVM_MONITOR_ENABLED)) {
      mJvmPauseMonitor = new JvmPauseMonitor(
          ServerConfiguration.getMs(PropertyKey.JVM_MONITOR_SLEEP_INTERVAL_MS),
          ServerConfiguration.getMs(PropertyKey.JVM_MONITOR_INFO_THRESHOLD_MS),
          ServerConfiguration.getMs(PropertyKey.JVM_MONITOR_WARN_THRESHOLD_MS));
      mJvmPauseMonitor.start();
    }
  }
442052
public function start()
    {
        declare (ticks = 1);
        register_shutdown_function(array($this, "shutdown"));
        pcntl_signal(SIGTERM, array($this, "signalHandler"));
        pcntl_signal(SIGINT, array($this, "signalHandler"));

        $this->output->writeln("<info>Starting <comment>".$this->config->getName()."</comment>.</info>");

        $this->dispatcher->dispatch(WorkerEvents::STARTED, new WorkerStartedEvent($this));

        // A dummy timer to keep a process on a system.
        $this->eventLoop->addPeriodicTimer(10, function () {});

        $this->output->writeln('<info>Successfully booted. Quit working with CONTROL-C.</info>');

        // Start event loop.
        $this->eventLoop->run();
    }
669741
def Main():
  """"""
  multiprocessing.freeze_support()

  tool = log2timeline_tool.Log2TimelineTool()

  if not tool.ParseArguments():
    return False

  if tool.show_info:
    tool.ShowInfo()
    return True

  if tool.show_troubleshooting:
    print('Using Python version {0!s}'.format(sys.version))
    print()
    print('Path: {0:s}'.format(os.path.abspath(__file__)))
    print()
    print(tool.GetVersionInformation())
    print()
    dependencies.CheckDependencies(verbose_output=True)

    print('Also see: https://plaso.readthedocs.io/en/latest/sources/user/'
          'Troubleshooting.html')
    return True

  have_list_option = False
  if tool.list_hashers:
    tool.ListHashers()
    have_list_option = True

  if tool.list_parsers_and_plugins:
    tool.ListParsersAndPlugins()
    have_list_option = True

  if tool.list_profilers:
    tool.ListProfilers()
    have_list_option = True

  if tool.list_timezones:
    tool.ListTimeZones()
    have_list_option = True

  if have_list_option:
    return True

  if tool.dependencies_check and not dependencies.CheckDependencies(
      verbose_output=False):
    return False

  try:
    tool.ExtractEventsFromSources()

  except (KeyboardInterrupt, errors.UserAbort):
    logging.warning('Aborted by user.')
    return False

  except (errors.BadConfigOption, errors.SourceScannerError) as exception:
    logging.warning(exception)
    return False

  return True
387257
function LoopStopManager() {

    //------------------------
    // MILLISECONDS
    //------------------------
    var START_MONITORING_AFTER = 2000;
    var STOP_ALL_MONITORING_TIMEOUT = 5000;
    var MAX_TIME_IN_LOOP_TILL_EXIT = 2200;

    // If we successfully run for X seconds no need to continue
    // to monitor because we know the program isn't locked
    var programNoLongerBeingMonitored = false;
    var programKilledSoStopMonitoring = false;
    var timeOfFirstCallToShouldStopLoop = 0;

    var loopExits = {};
    // Keep track of how long program spends in single loop w/o an exit
    var loopTimers = {};

    var t = {};

    t.shouldStopExecution = shouldStopExecution;
    t.exitedLoop = exitedLoop;

    return t;

    function shouldStopExecution(loopID) {

        var shouldStop = shouldStopLoop(loopID);

        if(shouldStop) {

            // TODO A temporary log.
            console.warn("An infinite loop (or a loop taking too long) was detected, so we stopped its execution. Sorry!");

        }

        return shouldStop;

    }

    function exitedLoop(loopID) {

        loopExits[loopID] = true;

    }

    function shouldStopLoop(loopID) {

        // Once we kill a loop, kill them all, we have an infinite loop and
        // it must be fixed prior to running again.
        if (programKilledSoStopMonitoring) {

            return true;

        }

        // Program exceeded monitor time, we're in the clear
        if (programNoLongerBeingMonitored) {

            return false;

        }

        // If the loopExit already called return
        // It's possible for the program to break out
        if (loopExits[loopID]) {

            return false;

        }

        var now = getTime();

        if (!timeOfFirstCallToShouldStopLoop) {

            timeOfFirstCallToShouldStopLoop = now;

            // first call to shouldStopLoop so just exit already
            return false;

        }

        var programRunningTime = now - timeOfFirstCallToShouldStopLoop;

        // Allow program to run unmolested (yup that's the right word)
        // while it starts up
        if (programRunningTime < START_MONITORING_AFTER) {

            return false;

        }

        // Once the program's run for a satisfactory amount of time
        // we assume it won't lock up and we can simply continue w/o
        // checking for infinite loops
        if (programRunningTime > STOP_ALL_MONITORING_TIMEOUT) {

            programNoLongerBeingMonitored = true;

            return false;

        }

        // Second level shit around new hotness logic
        try {

            checkOnInfiniteLoop(loopID, now);

        } catch(e) {

            programKilledSoStopMonitoring = true;

            return true;

        }

        return false;
    }

    function checkOnInfiniteLoop(loopID, now) {

        if (!loopTimers[loopID]) {

            loopTimers[loopID] = now;

            // We just started the timer for this loop. exit early
            return false;

        }

        var loopRunningTime = now - loopTimers[loopID];

        if (loopRunningTime > MAX_TIME_IN_LOOP_TILL_EXIT) {

            throw "Infinite Loop found on loop: " + loopID;

        }

    }

    function getTime() {

        return +new Date();

    }

}
325081
def watch_processes(self):
        

        for process in list(self.processes):
            self.watch_process(process)

        # Cleanup processes
        self.processes = [p for p in self.processes if not p.get("dead")]

        if self.stopping and len(self.processes) == 0:
            self.stop_watch()
896493
function Process(settings) {
    // save arguments
    this.settings = settings;

    // build args
    this.args = [settings.file].concat(settings.args || []);

    // build env
    this.env = helpers.mergeObject({}, settings.env || process.env);
    if (settings.options) {
      this.env.spawnOptions = JSON.stringify(settings.options);
    }

    // defaults properties
    this.closed = !!settings.close;
    this.suicide = false;
    this.pid = null;
    this.alive = false;

    // this streams will relay data from and to the process
    this.stderr = new streams.RelayStream({ paused: false });
    this.stdout = new streams.RelayStream({ paused: false });
    this.stdin = new streams.RelayStream({ paused: false });

    // relay io
    if (this.settings.ipc && helpers.support.pipeFork) {
      this.send = function () {
        this.process.send.apply(this.process, arguments);
      };
      this.flush = function () {};
    }
  }
1142749
def main():
    
    parser = getBasicOptionParser()
    initializeOptions(parser)
    options = parseBasicOptions(parser)
    checkOptions(options, parser)
    config = Config()
    config.setOptions(options)
    jobStore = Toil.resumeJobStore(config.jobStore)
    stats = getStats(jobStore)
    collatedStatsTag = processData(jobStore.config, stats)
    reportData(collatedStatsTag, options)
774203
def start_processes(self, max_restarts=-1):
        
        while 1:
            for process in self.processes:
                if not process:
                    # When process has not been started, start it
                    if not process.has_started:
                        process.start()
                        continue
                    # When process has stopped, start it again
                    exitcode = process.exitcode
                    if exitcode != 0:
                        # Process has been signaled or crashed
                        if exitcode > 0:
                            self.logger.error(
                                "Process '%s' with pid %d died with exitcode "
                                "%d", process.name, process.pid, exitcode
                            )
                        else:
                            self.logger.error(
                                "Process '%s' with pid %d died due to %s",
                                process.name, process.pid,
                                SIGNALS_TO_NAMES_DICT[abs(exitcode)]
                            )
                        # Max restarts has been reached, exit
                        if not max_restarts:
                            self.logger.fatal("Too many child restarts")
                            break
                        # Start process again
                        process.start()
                        # Decrement max_restarts counter
                        if max_restarts > 0:
                            max_restarts -= 1
                    else:
                        # Process has stopped without error
                        self.logger.info(
                            "Process '%s' with pid %d has stopped",
                            process.name, process.pid
                        )
                        # Start process again
                        process.start()
                        self.logger.info(
                            "Process '%s' has been started with pid %d",
                            process.name, process.pid
                        )
            else:
                time.sleep(0.25)
                continue
            break
907405
def Main():
  """"""
  multiprocessing.freeze_support()

  tool = psteal_tool.PstealTool()
  if not tool.ParseArguments():
    return False

  have_list_option = False

  if tool.list_timezones:
    tool.ListTimeZones()
    have_list_option = True

  if tool.list_output_modules:
    tool.ListOutputModules()
    have_list_option = True

  if tool.list_timezones:
    tool.ListTimeZones()
    have_list_option = True

  if tool.list_parsers_and_plugins:
    tool.ListParsersAndPlugins()
    have_list_option = True

  if tool.list_hashers:
    tool.ListHashers()
    have_list_option = True

  if tool.list_language_identifiers:
    tool.ListLanguageIdentifiers()
    have_list_option = True

  if have_list_option:
    return True

  try:
    tool.ExtractEventsFromSources()
    tool.AnalyzeEvents()

  except (KeyboardInterrupt, errors.UserAbort):
    logging.warning('Aborted by user.')
    return False

  except errors.SourceScannerError as exception:
    logging.warning(exception)
    return False

  return True