2023-06-27 17:58:12 +02:00
|
|
|
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):
|
2023-06-28 14:33:50 +02:00
|
|
|
print(
|
|
|
|
f"[main] Spawning {n} children in their own pools, each sleeping for {k} seconds"
|
|
|
|
)
|
2023-06-27 17:58:12 +02:00
|
|
|
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")
|
|
|
|
|
2023-06-28 14:33:50 +02:00
|
|
|
|
2023-06-27 17:58:12 +02:00
|
|
|
# Should exit in ~2 seconds
|
|
|
|
structio.run(main, 10, 2)
|