def test_acquires_blocking(c, s, a, b): lock = Lock('x') yield lock.acquire(blocking=False) assert lock.locked() yield lock.release() assert not lock.locked() with pytest.raises(ValueError): lock.acquire(blocking=False, timeout=1)
def test_acquires_blocking(c, s, a, b): lock = Lock("x") yield lock.acquire(blocking=False) assert lock.locked() yield lock.release() assert not lock.locked() with pytest.raises(ValueError): lock.acquire(blocking=False, timeout=1)
def test_acquires_with_zero_timeout(c, s, a, b): lock = Lock('x') yield lock.acquire(timeout=0) assert lock.locked() yield lock.release() yield lock.acquire(timeout=1) yield lock.release() yield lock.acquire(timeout=1) yield lock.release()
def test_acquires_with_zero_timeout(c, s, a, b): lock = Lock('x') yield lock.acquire(timeout=0) assert lock.locked() yield lock.release() yield lock.acquire(timeout=1) yield lock.release() yield lock.acquire(timeout=1) yield lock.release()
def test_timeout(c, s, a, b): locks = s.extensions['locks'] lock = Lock('x') yield lock.acquire() lock2 = Lock('x') assert lock.id != lock2.id start = time() with pytest.raises(gen.TimeoutError): yield lock2.acquire(timeout=0.1) stop = time() assert stop - start < 0.3 yield lock.release()
def test_lock_types(c, s, a, b): for name in [1, ('a', 1), ['a', 1], b'123', '123']: lock = Lock(name) assert lock.name == name yield lock.acquire() yield lock.release() assert not s.extensions['locks'].events
def test_lock_types(c, s, a, b): for name in [1, ("a", 1), ["a", 1], b"123", "123"]: lock = Lock(name) assert lock.name == name yield lock.acquire() yield lock.release() assert not s.extensions["locks"].events
def test_lock_types(c, s, a, b): for name in [1, ('a', 1), ['a', 1], b'123', '123']: lock = Lock(name) assert lock.name == name yield lock.acquire() yield lock.release() assert not s.extensions['locks'].events
def test_timeout(c, s, a, b): locks = s.extensions['locks'] lock = Lock('x') result = yield lock.acquire() assert result is True assert locks.ids['x'] == lock.id lock2 = Lock('x') assert lock.id != lock2.id start = time() result = yield lock2.acquire(timeout=0.1) stop = time() assert stop - start < 0.3 assert result is False assert locks.ids['x'] == lock.id assert not locks.events['x'] yield lock.release()
def test_timeout(c, s, a, b): locks = s.extensions['locks'] lock = Lock('x') result = yield lock.acquire() assert result is True assert locks.ids['x'] == lock.id lock2 = Lock('x') assert lock.id != lock2.id start = time() result = yield lock2.acquire(timeout=0.1) stop = time() assert stop - start < 0.3 assert result is False assert locks.ids['x'] == lock.id assert not locks.events['x'] yield lock.release()
def process(self, events): from distributed import worker_client, Variable, Lock assert isinstance(self.proc, BaseProcessor) assert not isinstance(self.proc, _Preheater) s = self.proc.get_dataset(events).data_source d = self.prefix + s with worker_client(separate_thread=False) as c: v = Variable(d, c) l = Lock(d, c) if l.acquire(blocking=False): self.proc.process(events) cols = set() for col in events.materialized: col = col.replace("_", ".", 1) try: attrgetter(col)(events) except AttributeError: pass else: cols.add(col) cols = sorted(cols) v.set(cols) return dict_accumulator({s: set_accumulator(cols)}) else: cols = v.get() for ag in map(attrgetter, cols): data = ag(events) data = getattr(data, "content", data) if callable(getattr(data, "materialize")): data.materialize() return dict_accumulator({})