def _cachedCheckAsset(bithorde, obj, t): dbStatus = hasValidStatus(obj, t) if dbStatus is None: return _checkAsset(bithorde, obj, t) else: concurrent.sleep() # Not sleeping here could starve other greenlets return obj, dbStatus
def test_DelayedAction(): ctr = MagicMock() a = DelayedAction(ctr) a.schedule(0.05) a.schedule(0.5) concurrent.sleep(0.1) ctr.assert_called_once_with()
def wait_for(condition, timeout=1): i = 0 interval = 0.01 while not condition(): i += interval if i > timeout: raise Exception("Timeout in wait_for(%s)" % condition) concurrent.sleep(interval)
def _run(self, interval, code): now = time() next = now + interval while self.running: concurrent.sleep(next - now) code() now = time() next = max(now, next + interval)
def _db_push(self, db_poll_interval): while self.running: with self._db.transaction(): for conn in self.connections.values(): try: conn.db_push() except IOError: logging.debug("Failed to push to %s, disconnecting", conn.peername) self.connections.pop(conn.peername, None) except Exception: logging.exception("%s push hit error", conn.peername) self.connections.pop(conn.peername, None) conn.shutdown() concurrent.sleep(db_poll_interval)
def _connector(self): def _connect(addr): try: return addr, concurrent.connect(addr) except Exception: return addr, None connectPool = concurrent.Pool(20) while self._sock: addresses = [ addr for addr, uuid in self._connectAddresses.iteritems() if uuid and (uuid not in self.connections) ] for address, sock in connectPool.imap(_connect, addresses): if sock: self._connectAddresses[address] = False concurrent.spawn(self._connectionWrapper, sock, address, address) concurrent.sleep(self.connect_interval)
def run(self): while self._step(): concurrent.sleep()