'This is a blocking call which will return a package which has
all dependencies met.  If interrupted or done it will return
None'

def get_valid_package(self):

    with self.condition:
        while ((not self.is_done()) and (len(self.to_build) > 0)):
            for p in self.to_build:
                dependencies_met = True
                for d in self.dependency_tracker.get_deps(p):
                    if ((d not in self.built) and (not (self.robust_build and (d in self.failed)))):
                        dependencies_met = False
                        break
                if dependencies_met:
                    self.to_build.remove(p)
                    self._started[p] = time.time()
                    self._hack_end_counter = 0
                    return p
                elif ((len(self._started) == 0) and (self._hack_end_counter > 2)):
                    return None
            self.condition.wait(1.0)
            self._hack_end_counter += 1
            if self.is_done():
                break
    return None
