34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import aiosched
|
|
from raw_catch import child_raises
|
|
from raw_wait import child as successful
|
|
|
|
|
|
|
|
async def main(
|
|
children_outer: list[tuple[str, int]], children_inner: list[tuple[str, int]]
|
|
):
|
|
before = aiosched.clock()
|
|
async with aiosched.with_context() as ctx:
|
|
print("[main] Spawning children in first context")
|
|
for name, delay in children_outer:
|
|
await ctx.spawn(successful, name, delay)
|
|
print("[main] Children spawned")
|
|
# An exception in an outer context cancels everything
|
|
# inside it, but an exception in an inner context does
|
|
# not affect outer ones
|
|
async with aiosched.with_context() as ctx2:
|
|
print("[main] Spawning children in second context")
|
|
for name, delay in children_inner:
|
|
await ctx2.spawn(child_raises, name, delay)
|
|
print("[main] Children spawned")
|
|
print(f"[main] Children exited in {aiosched.clock() - before:.2f} seconds")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
aiosched.run(
|
|
main,
|
|
[("first", 1), ("third", 3)],
|
|
[("second", 2), ("fourth", 4)],
|
|
debugger=None,
|
|
)
|