def test_basic_local(): """Basic local object support""" l = Local() l.foo = 0 values = [] def value_setter(idx): time.sleep(0.01 * idx) l.foo = idx time.sleep(0.02) values.append(l.foo) threads = [Thread(target=value_setter, args=(x,)) for x in [1, 2, 3]] for thread in threads: thread.start() time.sleep(0.2) assert sorted(values) == [1, 2, 3] def delfoo(): del l.foo delfoo() assert_raises(AttributeError, lambda: l.foo) assert_raises(AttributeError, delfoo) release_local(l)
def test_basic_local(): """Basic local object support""" l = Local() l.foo = 0 values = [] def value_setter(idx): time.sleep(0.01 * idx) l.foo = idx time.sleep(0.02) values.append(l.foo) threads = [Thread(target=value_setter, args=(x, )) for x in [1, 2, 3]] for thread in threads: thread.start() time.sleep(0.2) assert sorted(values) == [1, 2, 3] def delfoo(): del l.foo delfoo() assert_raises(AttributeError, lambda: l.foo) assert_raises(AttributeError, delfoo) release_local(l)
def test_local_release(): """Locals work without manager""" loc = Local() loc.foo = 42 release_local(loc) assert not hasattr(loc, "foo") ls = LocalStack() ls.push(42) release_local(ls) assert ls.top is None
def test_local_release(): """Locals work without manager""" loc = Local() loc.foo = 42 release_local(loc) assert not hasattr(loc, 'foo') ls = LocalStack() ls.push(42) release_local(ls) assert ls.top is None
def reset(self): release_local(self._local) for p in self._providers: p.reset()