def assign_processors(self):
        "hand out available processors to coordinators in order of need"
        margin = self.overload_margin - 1.0
        free_cpus = []
        nproc = {}
        for c in self.coordinators.values(): # COUNT NUMBER OF PROCS
            for host, pid in c.processors: # RUNNING ON EACH HOST
                try:
                    nproc[host] += 1.0 # INCREMENT AN EXISTING COUNT
                except KeyError:
                    nproc[host] = 1.0 # NEW, SO SET INITIAL COUNT
        for host in self.hosts: # BUILD LIST OF HOST CPUS TO BE ASSIGNED
            if host not in self.systemLoad: # ADDING A NEW HOST
                self.systemLoad[host] = 0.0 # DEFAULT LOAD: ASSUME HOST EMPTY
            try: # host MAY NOT BE IN nproc, SO CATCH THAT ERROR
                if self.systemLoad[host] > nproc[host]:
                    raise KeyError # USE self.systemLoad[host]
            except __HOLE__:
                load = self.systemLoad[host] # MAXIMUM VALUE
            else:
                load = nproc[host] # MAXIMUM VALUE
            if load < self.hosts[host].maxload + margin:
                free_cpus += int(self.hosts[host].maxload
                                 + self.overload_margin - load) * [host]
        if len(free_cpus) == 0: # WE DON'T HAVE ANY CPUS TO GIVE OUT
            return False
        l = [] # BUILD A LIST OF HOW MANY CPUS EACH COORDINATOR NEEDS
        for c in self.coordinators.values():
            ncpu = c.allocated_ncpu - len(c.processors)
            if ncpu > 0:
                l += ncpu*[c]  # ADD c TO l EXACTLY ncpu TIMES
        import random
        random.shuffle(l) # REORDER LIST OF COORDINATORS RANDOMLY
        i = 0 # INDEX INTO OUR l LIST
        while i < len(free_cpus) and i < len(l):
            # Hand out free CPUs one by one.
            l[i].new_cpus.append(free_cpus[i])
            i += 1
        return i > 0 # RETURN TRUE IF WE HANDED OUT SOME PROCESSORS
dataset/ETHPy150Open cjlee112/pygr/pygr/coordinator.py/ResourceController.assign_processors