Processes limit defintion
424115
private function processLimitDefinition()
    {
        if (isset($this->definition['limit'])) {
            
            // Upper and lower limit? Or a single value?
            if (is_array($this->definition['limit'])) {
                
                switch (count($this->definition['limit'])) {
                    
                    case 1:
                        $this->limit['lower'] = (int) $this->definition['limit'][0];
                        break;
                    
                    case 2:
                    default:
                        $this->limit['lower'] = (int) $this->definition['limit'][0];
                        $this->limit['upper'] = (int) $this->definition['limit'][1];
                        break;
                }
            } else {
                $this->limit['lower'] = $this->definition['limit'];
            }
        }
    }
111319
def limit_gen(limit, iterable):
  ''''''
  limit = int(limit)
  assert limit >= 0, 'negative limit'

  for item in iterable:
    if limit <= 0:
      break
    yield item
    limit -= 1
134313
def posargs_limiter(func, *args):
    
    posargs = inspect.getargspec(func)[0]
    length = len(posargs)
    if inspect.ismethod(func):
        length -= 1
    if length == 0:
        return func()
    return func(*args[0:length])
1362900
private void optimize(long fileLength) {

		final int availableProcessors = Runtime.getRuntime().availableProcessors();

		final long free = Runtime.getRuntime().freeMemory() / 2;

		int workerSize = availableProcessors / 2;
		if (workerSize < 2) {
			workerSize = 2;
		}

		long bufferSize = free / workerSize;
		if (bufferSize > 1 * 1024 * 1024) {
			bufferSize = 1 * 1024 * 1024;
		}

		long blockSize = fileLength / workerSize;
		if (blockSize > 1 * 1024 * 1024) {
			blockSize = 1 * 1024 * 1024;
		}
		int iBlockSize = (int) blockSize;

		if (bufferSize > blockSize) {
			bufferSize = blockSize;
		}
		int iBufferSize = (int) bufferSize;

		this.setBlockSize(iBlockSize);
		this.setMaxNumOfThreads(workerSize);
		this.setBufferSizePerWorker(iBufferSize);
		this.setSubBufferSize(256);

	}
1024648
boolean isProcessTreeOverLimit(ProcfsBasedProcessTree pTree, 
                                    String tId, long limit) {
    long currentMemUsage = pTree.getCumulativeVmem();
    // as processes begin with an age 1, we want to see if there are processes
    // more than 1 iteration old.
    long curMemUsageOfAgedProcesses = pTree.getCumulativeVmem(1);
    return isProcessTreeOverLimit(tId, currentMemUsage, 
                                  curMemUsageOfAgedProcesses, limit);
  }
1077894
def _setup_ulimit_time_limit(self, hardtimelimit, cgroups):
        """"""
        if hardtimelimit is not None:
            # Also use ulimit for CPU time limit as a fallback if cgroups don't work.
            if CPUACCT in cgroups:
                # Use a slightly higher limit to ensure cgroups get used
                # (otherwise we cannot detect the timeout properly).
                ulimit = hardtimelimit + _ULIMIT_DEFAULT_OVERHEAD
            else:
                ulimit = hardtimelimit
            resource.setrlimit(resource.RLIMIT_CPU, (ulimit, ulimit))
716961
def _limit(lower, upper):
    """"""
    if ((lower < 0) or (upper <= 0) or (upper < lower)):
        raise Exception("Illegal argument to _limit")
    return unicod("{%d,%d}") % (lower, upper)
145259
def offset_limit(func):
    

    def func_wrapper(self, start, stop):
        offset = start
        limit = stop - start
        return func(self, offset, limit)

    return func_wrapper
1141392
def _setup_file_hierarchy_limit(
            self, files_count_limit, files_size_limit, temp_dir, cgroups, pid_to_kill):
        """"""
        if files_count_limit is not None or files_size_limit is not None:
            file_hierarchy_limit_thread = FileHierarchyLimitThread(
                self._get_result_files_base(temp_dir),
                files_count_limit=files_count_limit,
                files_size_limit=files_size_limit,
                cgroups=cgroups,
                pid_to_kill=pid_to_kill,
                callbackFn=self._set_termination_reason,
                kill_process_fn=self._kill_process)
            file_hierarchy_limit_thread.start()
            return file_hierarchy_limit_thread
        return None
684237
def limits(action)
      @limits ||= {}
      limits = @limits[action.to_sym]
      raise TrafficJam::LimitNotFound.new(action) if limits.nil?
      limits
    end
501276
function stopOnProcess(index) {
  log( 'Attempting to stop ' + index + '...' );

  done = this.async();
  findProcessWithIndex( index, function(process) {
    if( typeof process !== 'undefined' ) {
      log( forever.format(true,[process]) );

      forever.stop( index )
        .on('stop', function() {
          done();
        })
        .on('error', function(message) {
          error( 'Error stopping ' + index + '. [REASON] :: ' + message );
          done(false);
        });
    }
    else {
      gruntRef.warn( index + ' not found in list of processes in forever.' );
      done();
    }
  });
}
148770
private synchronized void compareProgress(List<Long> processIds) {
        if (CollectionUtils.isEmpty(processIds) == false) {
            Long minProcessId = processIds.get(0);
            // 对比一下progress中的记录，如果小于当前最小的processId，直接删除内存中的记录
            // 因为发生跨机器调用或者出现restart指令，对应的process记录不会被删除
            for (Long processId : progress.keySet()) {
                if (processId < minProcessId) {
                    progress.remove(processId);
                }
            }
        }
    }
24059
def container_fs_limit_bytes(self, metric, scraper_config):
        
        pct_m_name = scraper_config['namespace'] + '.filesystem.usage_pct'
        if metric.type not in METRIC_TYPES:
            self.log.error("Metric type %s unsupported for metric %s" % (metric.type, metric.name))
            return
        self._process_limit_metric('', metric, self.fs_usage_bytes, scraper_config, pct_m_name)
791258
def runInParallel(*fns):
        
        proc = []
        for fn in fns:
            p = Process(target=fn)
            p.start()
            proc.append(p)
        for p in proc:
            p.join()
488111
def limit(self, limit):
    
    params = join_params(self.parameters, {"limit": limit})

    return self.__class__(**params)
1275142
public static void getBufferLimits(WsByteBuffer[] buffers, int[] limits) {
        // Double check that the parameters are non null.
        if ((buffers != null) && (limits != null)) {
            // Loop through the buffers.
            // In case of errant parameters, protect from array out of bounds.
            for (int i = 0; i < buffers.length && i < limits.length; i++) {
                // Double check for null buffers.
                if (buffers[i] != null) {
                    // Save the limit.
                    limits[i] = buffers[i].limit();
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "getBufferLimits: buffer[" + i + "] limit of " + limits[i]);
                    }
                } else {
                    // When buffer is null, save a limit of 0.
                    limits[i] = 0;
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "getBufferLimits: null buffer[" + i + "] limit of " + limits[i]);
                    }
                }
            }
        }
    }
654949
def rate_limit(self, rate_limit):
        
        self._rate_limit = bool(rate_limit)
        self._rate_limit_last_call = None
        self.clear_memoized()