def f(i): with worker_client() as c: q = Queue('x', client=c) for _ in range(100): future = q.get() x = future.result() y = c.submit(inc, x) q.put(y) sleep(0.01) result = q.get().result() return result
def f(i): with worker_client() as c: q = Queue("x", client=c) for _ in range(100): future = q.get() x = future.result() y = c.submit(inc, x) q.put(y) sleep(0.01) result = q.get().result() return result
def test_erred_future(c, s, a, b): future = c.submit(div, 1, 0) q = Queue() yield q.put(future) yield gen.sleep(0.1) future2 = yield q.get() with pytest.raises(ZeroDivisionError): yield future2.result()
class DistStatusReporter(object): """Report status through the training scheduler. Example ------- >>> @autogluon_method >>> def train_func(config, reporter): ... reporter(accuracy=0.1) """ def __init__(self, remote=None): self._queue = Queue(client=remote) self._stop = Variable(client=remote) self._stop.set(False) self._continue_semaphore = DistSemaphore(0, remote) def __call__(self, **kwargs): """Report updated training status. Pass in `done=True` when the training job is completed. Args: kwargs: Latest training result status. Example _______ >>> reporter(accuracy=1, training_iters=4) """ logger.debug('Reporting {}'.format(json.dumps(kwargs))) try: self._queue.put(kwargs.copy()) except RuntimeError: return self._continue_semaphore.acquire() if self._stop.get(): raise AutoGluonEarlyStop('Stopping!') def fetch(self, block=True): try: kwargs = self._queue.get() except CommClosedError: return {} return kwargs def terminate(self): self._stop.set(True) self._continue_semaphore.release() def move_on(self): self._continue_semaphore.release() def save_dict(self, **state_dict): raise NotImplementedError def get_dict(self): raise NotImplementedError def __repr__(self): reprstr = self.__class__.__name__ return reprstr
def test_picklability_sync(client): q = Queue() def f(x): q.put(x + 1) client.submit(f, 10).result() assert q.get() == 11
def test_picklability(c, s, a, b): q = Queue() def f(x): q.put(x + 1) yield c.submit(f, 10) result = yield q.get() assert result == 11
def test_sync(client): future = client.submit(lambda x: x + 1, 10) x = Queue("x") xx = Queue("x") x.put(future) assert x.qsize() == 1 assert xx.qsize() == 1 future2 = xx.get() assert future2.result() == 11
def test_sync(client): future = client.submit(lambda x: x + 1, 10) x = Queue('x') xx = Queue('x') x.put(future) assert x.qsize() == 1 assert xx.qsize() == 1 future2 = xx.get() assert future2.result() == 11
def test_picklability_sync(loop): with cluster() as (s, [a, b]): with Client(s['address']) as c: q = Queue() def f(x): q.put(x + 1) c.submit(f, 10).result() assert q.get() == 11
def test_erred_future(c, s, a, b): future = c.submit(div, 1, 0) q = Queue() yield q.put(future) yield gen.sleep(0.1) future2 = yield q.get() with pytest.raises(ZeroDivisionError): yield future2.result() exc = yield future2.exception() assert isinstance(exc, ZeroDivisionError)
def test_sync(loop): with cluster() as (s, [a, b]): with Client(s['address']) as c: future = c.submit(lambda x: x + 1, 10) x = Queue('x') xx = Queue('x') x.put(future) assert x.qsize() == 1 assert xx.qsize() == 1 future2 = xx.get() assert future2.result() == 11
def test_same_futures(c, s, a, b): q = Queue('x') future = yield c.scatter(123) for i in range(5): yield q.put(future) assert s.wants_what['queue-x'] == {future.key} for i in range(4): future2 = yield q.get() assert s.wants_what['queue-x'] == {future.key} yield gen.sleep(0.05) assert s.wants_what['queue-x'] == {future.key} yield q.get() start = time() while s.wants_what['queue-x']: yield gen.sleep(0.01) assert time() - start < 2
def test_Queue(c, s, a, b): assert s.address.startswith("tls://") x = Queue("x") y = Queue("y") size = yield x.qsize() assert size == 0 future = c.submit(inc, 1) yield x.put(future) future2 = yield x.get() assert future.key == future2.key
def test_Queue(c, s, a, b): assert s.address.startswith('tls://') x = Queue('x') y = Queue('y') size = yield x.qsize() assert size == 0 future = c.submit(inc, 1) yield x.put(future) future2 = yield x.get() assert future.key == future2.key
def test_timeout(c, s, a, b): q = Queue('v', maxsize=1) start = time() with pytest.raises(gen.TimeoutError): yield q.get(timeout=0.3) stop = time() assert 0.2 < stop - start < 2.0 yield q.put(1) start = time() with pytest.raises(gen.TimeoutError): yield q.put(2, timeout=0.3) stop = time() assert 0.1 < stop - start < 2.0
class DistSemaphore(object): def __init__(self, value, remote=None): self._queue = Queue(client=remote) for i in range(value): self._queue.put(1) def acquire(self): try: _ = self._queue.get() except distributed.comm.core.CommClosedError: pass def release(self): self._queue.put(1) def __repr__(self): reprstr = self.__class__.__name__ return reprstr
def foo(): y = Queue("x") return y.get()