structio/tests/scope_tree.py

24 lines
588 B
Python

import structio
async def child(k):
print("[child] I'm alive! Spawning sleeper")
async with structio.create_pool() as p:
p.spawn(structio.sleep, k)
print("[child] I'm done sleeping!")
async def main(n: int, k):
print(
f"[main] Spawning {n} children in their own pools, each sleeping for {k} seconds"
)
t = structio.clock()
async with structio.create_pool() as p:
for _ in range(n):
p.spawn(child, k)
print(f"[main] Done in {structio.clock() - t:.2f} seconds")
# Should exit in ~2 seconds
structio.run(main, 10, 2)