structio/tests/shields.py

23 lines
619 B
Python
Raw Normal View History

import structio
async def shielded(i):
print("[shielded] Entering shielded section")
with structio.TaskScope(shielded=True) as s:
await structio.sleep(i)
print(f"[shielded] Slept {i} seconds")
s.shielded = False
print(f"[shielded] Exited shielded section, sleeping {i} more seconds")
await structio.sleep(i)
async def main(i):
print(f"[main] Parent has started, finishing in {i} seconds")
t = structio.clock()
with structio.skip_after(1):
await shielded(i)
print(f"[main] Exited in {structio.clock() - t:.2f} seconds")
structio.run(main, 5)