create function to check that all workers are dead.
432410
function() {
            if (_.keys(children).length == 0) {
              that.stop(process.exit);
            }
            else {
              setImmediate(checkExit);   // keep polling for safe shutdown.
            }
          }
727802
def main():
    """"""
    def die((x, y)):
        """Pretend any out-of-bounds cell is dead."""
        if 0 <= x < width and 0 <= y < height:
            return x, y

    LOAD_FACTOR = 9  # Smaller means more crowded.
    NUDGING_LOAD_FACTOR = LOAD_FACTOR * 3  # Smaller means a bigger nudge.

    term = Terminal()
    width = term.width
    height = term.height
    board = random_board(width - 1, height - 1, LOAD_FACTOR)
    detector = BoredomDetector()
    cells = cell_strings(term)

    with nested(term.fullscreen(), term.hidden_cursor()):
        try:
            while True:
                frame_end = time() + 0.05
                board = next_board(board, die)
                draw(board, term, cells)

                # If the pattern is stuck in a loop, give it a nudge:
                if detector.is_bored_of(board):
                    board.update(random_board(width - 1,
                                              height - 1,
                                              NUDGING_LOAD_FACTOR))

                stdout.flush()
                sleep_until(frame_end)
                clear(board, term, height)
        except KeyboardInterrupt:
            pass
560651
def reap_all_workers(waitpid_flags=Process::WNOHANG)
      @waiting_for_reaper = waitpid_flags == 0
      begin
        loop do
          # -1, wait for any child process
          wpid, status = Process.waitpid2(-1, waitpid_flags)
          break unless wpid

          if worker = delete_worker(wpid)
            log "Reaped resque worker[#{status.pid}] (status: #{status.exitstatus}) queues: #{worker.queues.join(",")}"
          else
            # this died before it could be killed, so it's not going to have any extra info
            log "Tried to reap worker [#{status.pid}], but it had already died. (status: #{status.exitstatus})"
          end
        end
      rescue Errno::ECHILD, QuitNowException
      end
    end
850759
def killall(self, wait = None):
        
        with self.tasks.mutex:
            self.tasks.queue.clear()
        self.count_lock.acquire()
        self.kill(self.workers)
        self.count_lock.release()
        self.kill_event.wait(wait)
1088797
def update_workers(self):
        """"""
        for expiration in self.worker_manager.inspect_workers():
            self.handle_worker_expiration(expiration)

        self.worker_manager.create_workers()
587240
def wait_for_workers(seconds)
      seconds.times do
        logger.info("Shutting down... waiting for workers to die (we have #{seconds} seconds)...")
        running_total = 0

        @worker_pools.each do |name, pool|
          running_total += pool.wait_workers
        end

        if running_total.zero?
          logger.info("All workers are dead. Exiting...")
          return true
        end

        logger.info("#{running_total} workers are still running! Sleeping for a second...")
        sleep(1)
      end

      return false
    end
580786
def dead(cls, reason=None, **kwargs):
        
        kwargs['data'], _ = UTF8_CODEC.encode(reason or u'')
        return cls(reply_to=IS_DEAD, **kwargs)
463288
def on_terminate(func):
    """"""
    def exit_function(*args):
        func()
        exit(0)
    signal.signal(signal.SIGTERM, exit_function)
71838
function checkIfNoWorkersAndExit() {
            if (!currentWorkersCount) {
                log('Cluster graceful shutdown: done.');
                if (shutdownTimer) clearTimeout(shutdownTimer);
                exitFunction();
            } else {
                log('Cluster graceful shutdown: wait ' + currentWorkersCount + ' worker' + (currentWorkersCount > 1 ? 's' : '') + '.');
            }
        }
627785
def join(timeout = 5)
      while (worker = workers.first)
        if worker.join(timeout)
          # Worker thread is dead
          workers.shift
        else
          return false
        end
      end
      true
    end
1314806
def maintain_worker_count
      all_known_queues.each do |queues|
        delta = worker_delta_for(queues)
        spawn_missing_workers_for(queues) if delta > 0
        quit_excess_workers_for(queues)   if delta < 0
      end
    end
691930
function createWorker() {
    var worker = new Worker('worker.js');

    // On worker messsage
    worker.onmessage = function(event) {
        if (event.data.event === 'done') {
            console.log('done:', event.data.data);
            $('#start').show();
            $('#abort').hide();
        }
        else if (event.data.event === 'progress') {
            console.log('progress:', event.data.data.percent, '%');
        }
    };

    return worker;
}
449008
function stopRespawning() {
        Object.keys(cluster.workers).forEach(function (id) {
            cluster.workers[id].removeAllListeners("exit");
        });
    }
688168
def mark_dead(self, connection, now=None):
        
        # allow inject for testing purposes
        now = now if now else time.time()
        try:
            self.connections.remove(connection)
        except ValueError:
            # connection not alive or another thread marked it already, ignore
            return
        else:
            dead_count = self.dead_count.get(connection, 0) + 1
            self.dead_count[connection] = dead_count
            timeout = self.dead_timeout * 2 ** min(dead_count - 1,
                                                   self.timeout_cutoff)
            self.dead.put((now + timeout, connection))
            logger.warning(
                'Connection %r has failed for %i times in a row,'
                ' putting on %i second timeout.',
                connection, dead_count, timeout
            )
84471
function(worker) {
      var data = getWorkerNamespacedData(worker);

      Object.keys(data.pending).forEach(function(seqNum) {
        var item = data.pending[seqNum];
        delete data.pending[seqNum];
        if (item[0].monitored) {
          item[1](new Error("Undeliverable message: worker died before we could get acknowledgement"));
        }
      });
    }
728567
function startWorkers(instances) {
	let stopping = false;

	cluster.on("exit", function(worker, code) {
		if (!stopping) {
			// only restart the worker if the exit was by an error
			if (production && code !== 0) {
				logger.info(`The worker #${worker.id} has disconnected`);
				logger.info(`Worker #${worker.id} restarting...`);
				cluster.fork();
				logger.info(`Worker #${worker.id} restarted`);
			} else {
				process.exit(code);
			}
		}
	});

	const workerCount = Number.isInteger(instances) && instances > 0 ? instances : os.cpus().length;

	logger.info(`Starting ${workerCount} workers...`);

	for (let i = 0; i < workerCount; i++) {
		cluster.fork();
	}

	stopSignals.forEach(function (signal) {
		process.on(signal, () => {
			logger.info(`Got ${signal}, stopping workers...`);
			stopping = true;
			cluster.disconnect(function () {
				logger.info("All workers stopped, exiting.");
				process.exit(0);
			});
		});
	});
}
1084383
protected function validate_lib_workers() {

        foreach ($this->functions as $func => $props) {
            require_once $props["path"];
            $real_func = $this->prefix.$func;
            if (!function_exists($real_func) &&
               (!class_exists($real_func) || !method_exists($real_func, "run"))) {
                $this->log("Function $real_func not found in ".$props["path"]);
                posix_kill($this->pid, SIGUSR2);
                exit();
            }
        }

    }