Set the maximum workers to create.
762964
def set_max_workers(self, nb):
        
        self.count_lock.acquire()
        self.max_workers = nb
        if self.workers > self.max_workers:
            self.kill(self.workers - self.max_workers)
        self.count_lock.release()
576178
def grow(self, amount):
        """"""
        if self.max > 0:
            budget = max(self.max - len(self._threads), 0)
        else:
            # self.max <= 0 indicates no maximum
            budget = float('inf')

        n_new = min(amount, budget)

        workers = [self._spawn_worker() for i in range(n_new)]
        while not all(worker.ready for worker in workers):
            time.sleep(.1)
        self._threads.extend(workers)
177546
def dismissWorkers(self, num_workers):
        """"""
        for i in range(min(num_workers, len(self.workers))):
            worker = self.workers.pop()
            worker.dismiss()
219370
def work(self):
        
        self.work_init()

        self.work_loop(max_jobs=self.max_jobs, max_time=self.max_time)

        self.work_stop()
868479
public final void setMax(final int max) {
		if (max < 0) {
			throw new IllegalArgumentException(ILLEGAL_MAX);
		}
		if (max != getMax()) {
			getOrCreateComponentModel().max = max;
		}
	}
76097
@CommandArgument
  public void setcpus(int numberOfCpus) {
    if (worker == null) {
      System.err.println("Worker not running.");
      return;
    }
    int availableCpus = Runtime.getRuntime().availableProcessors();
    if (numberOfCpus <= 0 || numberOfCpus > availableCpus) {
      numberOfCpus = availableCpus;
    }
    System.out.printf("Setting number of CPUs to %d\n", numberOfCpus);
    worker.setMaxWorkers(numberOfCpus);
  }
373332
public function start()
    {
        if ($this->isRunning()) {
            throw new StatusError('The worker pool has already been started.');
        }

        // Start up the pool with the minimum number of workers.
        $count = $this->minSize;
        while (--$count >= 0) {
            $worker = $this->createWorker();
            $this->idleWorkers->enqueue($worker);
        }

        $this->running = true;
    }
774995
def select_build_worker(self, pos: Union[Unit, Point2, Point3], force: bool=False) -> Optional[Unit]:
        """"""

        workers = self.workers.closer_than(20, pos) or self.workers
        for worker in workers.prefer_close_to(pos).prefer_idle:
            if not worker.orders or len(worker.orders) == 1 and worker.orders[0].ability.id in {AbilityId.MOVE,
                                                                                                AbilityId.HARVEST_GATHER,
                                                                                                AbilityId.HARVEST_RETURN}:
                return worker

        return workers.random if force else None
414637
def apply(self, func, workers=1, job_size=10000):
    
    if workers == 1:
      for lines in self.iter_chunks(job_size):
        yield func(lines)
    else:
      with ProcessPoolExecutor(max_workers=workers) as executor:
        for result in executor.map(func, self.iter_chunks(job_size)):
          yield result
1356578
def adjust_worker_number_by_load(self):
        
        if self.interrupted:
            logger.debug("Trying to adjust worker number. Ignoring because we are stopping.")
            return

        to_del = []
        logger.debug("checking worker count."
                     " Currently: %d workers, min per module : %d, max per module : %d",
                     len(self.workers), self.min_workers, self.max_workers)

        # I want at least min_workers by module then if I can, I add worker for load balancing
        for mod in self.q_by_mod:
            # At least min_workers
            todo = max(0, self.min_workers - len(self.q_by_mod[mod]))
            for _ in range(todo):
                try:
                    self.create_and_launch_worker(module_name=mod)
                # Maybe this modules is not a true worker one.
                # if so, just delete if from q_by_mod
                except NotWorkerMod:
                    to_del.append(mod)
                    break

        for mod in to_del:
            logger.warning("The module %s is not a worker one, I remove it from the worker list.",
                           mod)
            del self.q_by_mod[mod]
343559
private void adjustPoolSize() {
        if (lastCheck + 1000 < System.currentTimeMillis()) {
            int n = Runtime.getRuntime().availableProcessors();
            if (numProcessors != n) {
                executor.setMaximumPoolSize(n);
                numProcessors = n;
            }
            lastCheck = System.currentTimeMillis();
        }
    }
897948
def worker(n):
    """"""
    for _ in xrange(999999):
        a = exp(n)
        b = exp(2*n)
    return n, a
266965
private static int setReducerCount(long fileCount, JobConf job, 
      JobClient client) {
    // calculate the max number of reducers.
    int numReducers = Math.max(job.getInt(MAX_REDUCE_LABEL, MAX_REDUCERS_DEFAULT),
        (int) (fileCount / job.getInt(MAX_FILES_PER_REDUCER_LABEL, 
            MAX_FILES_PER_REDUCER_DEFAULT)));
    
    // make sure we at least have 1.
    numReducers = Math.max(numReducers, 1);
    job.setNumReduceTasks(numReducers);
    return numReducers;
  }
1053874
public function setMemoryLimit($memoryLimit)
    {
        if ($this->status != self::STATUS_NEW) {
            throw new \RuntimeException('Cannot set worker memory limit after worker has started working');
        }

        $this->memoryLimit = $memoryLimit;
    }
1035124
def set_max_threads(self, max_threads):
        
        if max_threads is None:
            raise TypeError('max_threads must not be None.')
        self._check_if_ready()
        self.collection.set_max_working(max_threads)
758621
public void setMaximumInstances(int maximumInstances) {
        int newValue = maximumInstances < 0 ? 0 : maximumInstances;

        if (this.maximumInstances != newValue) {
            this.maximumInstances = newValue;

            getConfig().setProperty(PARAM_MAXIMUM_INSTANCES, this.maximumInstances);
        }
    }
1176923
def set_max_workers(self, nb):
        
        self.count_lock.acquire()
        self.shared['max_workers'] = nb
        if self.shared['workers'] > self.shared['max_workers']:
            self.kill(self.shared['workers'] - self.shared['max_workers'])
        self.count_lock.release()