def waitForResults(graph, values, timeout=60.0): """wait for 'x' to have 'result' not be zero. return the maximum number of CPUs ever observed to be allocated to 'x'""" t0 = time.time() def notLoadedCount(): notLoadedCount = 0 for x in values: if x.valueIVC is None: notLoadedCount += 1 return notLoadedCount with IncreasedRequestCount(values): maxCPUs = None while notLoadedCount() > 0 and time.time() - t0 < timeout: time.sleep(.01) BackgroundUpdateQueue.pullOne(timeout=.10) graph.flush() for x in values: if x.totalWorkerCount is not None: if maxCPUs is None: maxCPUs = x.totalWorkerCount else: maxCPUs = max(maxCPUs, x.totalWorkerCount) assert notLoadedCount( ) == 0, "Timed out: %s of %s didn't finish:\n\t%s\n" % ( notLoadedCount(), len(values), "\n\t".join( [str(x) for x in values if x.valueIVC is None])) return maxCPUs
def waitUntilTrue(self, predicate, timeout=10.0): t0 = time.time() interval = 0.001 while not predicate(): time.sleep(interval) BackgroundUpdateQueue.pullOne(timeout=interval) self.graph.flush() if time.time() - t0 > timeout: self.assertFalse(True, "timed out") return interval = min(interval * 2, 0.1)
def waitUntilTrue(self, predicate, timeout = 10.0): t0 = time.time() interval = 0.001 while not predicate(): time.sleep(interval) BackgroundUpdateQueue.pullOne(timeout = interval) self.graph.flush() if time.time() - t0 > timeout: self.assertFalse(True, "timed out") return interval = min(interval * 2, 0.1)
def waitCacheItemsAreLoaded(graph, cacheItems, timeout = 60.0): with IncreasedRequestCount(cacheItems): def allAreLoaded(): for c in cacheItems: if not c.isLoaded: return False return True t0 = time.time() while not allAreLoaded() and time.time() - t0 < timeout: BackgroundUpdateQueue.pullOne(timeout = 1.0) graph.flush() assert allAreLoaded(), "Timed out"
def waitCacheItemsAreLoaded(graph, cacheItems, timeout=60.0): with IncreasedRequestCount(cacheItems): def allAreLoaded(): for c in cacheItems: if not c.isLoaded: return False return True t0 = time.time() while not allAreLoaded() and time.time() - t0 < timeout: BackgroundUpdateQueue.pullOne(timeout=1.0) graph.flush() assert allAreLoaded(), "Timed out"
def waitForResults(graph, values, timeout = 60.0): """wait for 'x' to have 'result' not be zero. return the maximum number of CPUs ever observed to be allocated to 'x'""" t0 = time.time() def notLoadedCount(): notLoadedCount = 0 for x in values: if x.valueIVC is None: notLoadedCount += 1 return notLoadedCount with IncreasedRequestCount(values): maxCPUs = None while notLoadedCount() > 0 and time.time() - t0 < timeout: time.sleep(.01) BackgroundUpdateQueue.pullOne(timeout = .10) graph.flush() for x in values: if x.totalWorkerCount is not None: if maxCPUs is None: maxCPUs = x.totalWorkerCount else: maxCPUs = max(maxCPUs,x.totalWorkerCount) assert notLoadedCount() == 0, "Timed out: %s of %s didn't finish:\n\t%s\n" % ( notLoadedCount(), len(values), "\n\t".join( [str(x) for x in values if x.valueIVC is None] ) ) return maxCPUs
def waitCacheItemIsLoaded(graph, cacheItem): with IncreasedRequestCount(cacheItem): while not cacheItem.isLoaded: BackgroundUpdateQueue.pullOne() graph.flush()