| 55 | |
| 56 | |
| 57 | def test_basic_local_asyncio(): |
| 58 | ns = local.Local(_cv_ns) |
| 59 | ns.foo = 0 |
| 60 | values = [] |
| 61 | |
| 62 | async def value_setter(idx): |
| 63 | await asyncio.sleep(0.01 * idx) |
| 64 | ns.foo = idx |
| 65 | await asyncio.sleep(0.02) |
| 66 | values.append(ns.foo) |
| 67 | |
| 68 | async def main(): |
| 69 | futures = [asyncio.ensure_future(value_setter(i)) for i in [1, 2, 3]] |
| 70 | await asyncio.gather(*futures) |
| 71 | |
| 72 | asyncio.run(main()) |
| 73 | assert sorted(values) == [1, 2, 3] |
| 74 | |
| 75 | def delfoo(): |
| 76 | del ns.foo |
| 77 | |
| 78 | delfoo() |
| 79 | pytest.raises(AttributeError, lambda: ns.foo) |
| 80 | pytest.raises(AttributeError, delfoo) |
| 81 | |
| 82 | local.release_local(ns) |
| 83 | |
| 84 | |
| 85 | def test_local_release(): |