Ensure there are enough workers available
971077
def _ensure_worker(self):
        """"""
        while len(self._workers) < self._min_workers or len(self._workers) < self._queue.qsize() < self._max_workers:
            worker = threading.Thread(
                target=self._execute_futures,
                name=self.identifier + '_%d' % time.time(),
            )
            worker.daemon = True
            self._workers.add(worker)
            worker.start()
609962
def init_workers():
    """"""
    setproctitle('oq-worker')
    # unregister raiseMasterKilled in oq-workers to avoid deadlock
    # since processes are terminated via pool.terminate()
    signal.signal(signal.SIGTERM, signal.SIG_DFL)
    # prctl is still useful (on Linux) to terminate all spawned processes
    # when master is killed via SIGKILL
    try:
        import prctl
    except ImportError:
        pass
    else:
        # if the parent dies, the children die
        prctl.set_pdeathsig(signal.SIGKILL)
20429
def wait_for_jobs(jobs):
    

    all_running = False
    while not all_running:
        all_running = True
        time.sleep(5)
        for job in jobs:
            job.refresh()
            scheduled = getattr(job, "scheduled_at", None)
            if scheduled is not None:
                logger.info("Waiting for %s on %s [%s]" % (job.uid,
                                                           job.site,
                                                           _date2h(scheduled)))
            all_running = all_running and job.state == "running"
            if job.state == "error":
                raise Exception("The job %s is in error state" % job)
    logger.info("All jobs are Running !")
870435
function ( prepData, workerSupportExternal ) {
		this._applyPrepData( prepData );
		var available = prepData.checkResourceDescriptorFiles( prepData.resources,
			[
				{ ext: "obj", type: "ArrayBuffer", ignore: false },
				{ ext: "mtl", type: "String", ignore: false },
				{ ext: "zip", type: "String", ignore: true }
			]
		);
		if ( THREE.LoaderSupport.Validator.isValid( workerSupportExternal ) ) {

			this.terminateWorkerOnLoad = false;
			this.workerSupport = workerSupportExternal;
			this.logging.enabled = this.workerSupport.logging.enabled;
			this.logging.debug = this.workerSupport.logging.debug;

		}
		var scope = this;
		var onMaterialsLoaded = function ( materials ) {
			if ( materials !== null ) scope.meshBuilder.setMaterials( materials );
			scope._loadObj( available.obj, scope.callbacks.onLoad, null, null, scope.callbacks.onMeshAlter, prepData.useAsync );

		};
		this._loadMtl( available.mtl, onMaterialsLoaded, null, null, prepData.crossOrigin, prepData.materialOptions );
	}
563684
def qualify(workers, qualification, value, by_name, notify, sandbox):
    """"""
    if not (workers and qualification and value):
        raise click.BadParameter(
            "Must specify a qualification ID, value/score, and at least one worker ID"
        )
    mturk = _mturk_service_from_config(sandbox)
    if by_name:
        result = mturk.get_qualification_type_by_name(qualification)
        if result is None:
            raise click.BadParameter(
                'No qualification with name "{}" exists.'.format(qualification)
            )

        qid = result["id"]
    else:
        qid = qualification

    click.echo(
        "Assigning qualification {} with value {} to {} worker{}...".format(
            qid, value, len(workers), "s" if len(workers) > 1 else ""
        )
    )
    for worker in workers:
        if mturk.set_qualification_score(qid, worker, int(value), notify=notify):
            click.echo("{} OK".format(worker))

    # print out the current set of workers with the qualification
    results = list(mturk.get_workers_with_qualification(qid))

    click.echo("{} workers with qualification {}:".format(len(results), qid))

    for score, count in Counter([r["score"] for r in results]).items():
        click.echo("{} with value {}".format(count, score))
782300
public function moreOrLess($total, $available)
    {
        $shouldHaveMoreWorkers = false;
        $shouldHaveLessWorkers = false;
        $minWorkers = $this->input->getOption('min-workers');
        $maxWorkers = $this->input->getOption('max-workers');
        $spareWorkers = $this->input->getOption('spare-workers');
        if ($total < $minWorkers) {
            //too little workers,spawn more please
            $shouldHaveMoreWorkers = true;
            $this->verboseOutput("<info>Too little workers</info>: $total / $minWorkers");
        } elseif (($available < $spareWorkers) && ($total <= $maxWorkers)) {
            //we have not enough spare workers we should spawn some more... unless we have reached the max workers limit
            $shouldHaveMoreWorkers = true;
            $this->verboseOutput("<info>Too little spare workers</info>: $available / $spareWorkers");
        } elseif ($total >= $maxWorkers) {
            //we should have less workers because we somehow ended up over the limit
            $shouldHaveLessWorkers = true;
        } elseif ($available >= $minWorkers + $spareWorkers && !$shouldHaveMoreWorkers) {
            //we have more than enough workers for the amount of work we should probably kill one off.
            $shouldHaveLessWorkers = true;
        }
        return array($shouldHaveLessWorkers, $shouldHaveMoreWorkers);
    }
368797
def grow(self, amount):
        """"""
        for i in range(amount):
            if self.max > 0 and len(self._threads) >= self.max:
                break
            worker = WorkerThread(self.server)
            worker.setName("CP Server " + worker.getName())
            self._threads.append(worker)
            worker.start()
1181950
protected function checkJobLimit()
    {
        // Make sure we don't run more than maxJobs jobs on this worker:
        $this->totalJobs++;

        if ($this->maxJobs != -1 && $this->maxJobs <= $this->totalJobs) {
            $this->stopWorker();
        }
    }
573961
public function reserve()
    {
        foreach ($this->queues as $queue) {
            $this->getLogger()->debug(
                'Checking {queue} for jobs',
                array(
                    'queue' => $queue
                )
            );
            $job = $queue->dequeue();
            if (false === (null === $job)) {
                $this->getLogger()->info(
                    'Found job {job} on queue {queue}',
                    array(
                        'job' => $job,
                        'queue' => $queue,
                    )
                );

                return $job;
            }
        }

        return null;
    }
1024461
def pending_tasks(self, res):
        ""
        jobs, lock = self._jobs
        with lock:
            return jobs[res].copy()
526309
def make_ready(self):
        """"""
        SCons.Taskmaster.OutOfDateTask.make_ready(self)
        if self.out_of_date and self.options.debug_explain:
            explanation = self.out_of_date[0].explain()
            if explanation:
                sys.stdout.write("scons: " + explanation)
1205833
def num_available(self, work_spec_name):
        '''

        '''
        return self.registry.len(WORK_UNITS_ + work_spec_name,
                                 priority_max=time.time())
126544
def setup(self, workers=1, qsize=0):
        """"""
        if workers <= 0:
            raise ValueError("workers have to be greater then zero")
        if qsize < 0:
            raise ValueError("qsize have to be greater or equal zero")
        self.qsize = qsize # output que size
        self.workers = workers
        return self
916047
def ask(op, *args)
      if :add == op && 0 < @max_job_count && (@work_queue.size() + @queue.size()) >= @max_job_count
        unless 0.0 >= @job_timeout
          @add_thread = Thread.current
          give_up_at = Time.now + @job_timeout
          until Time.now > give_up_at || (@work_queue.size() + @queue.size()) < @max_job_count
            sleep(@job_timeout)
          end
          @add_thread = nil
        end
        raise BusyError.new() unless @work_queue.size() < @max_job_count
      end
      super
    end
1060976
def setNumWorkers(self, num_workers):
        """"""
        cur_num = len(self.workers)
        if cur_num > num_workers:
            self.dismissWorkers(cur_num - num_workers)
        else:
            self.createWorkers(num_workers - cur_num)
679785
def add(job)
      if @workers.empty?
        @work_queue.insert(0, job)
      else
        worker = @workers.pop()
        ask_worker(worker, job)
      end
    end
585912
def process(job = nil, &block)
      return unless job ||= reserve

      job.worker = self
      working_on job
      perform(job, &block)
    ensure
      done_working
    end