import aiosched from catch import child as errorer from wait import child as successful from debugger import Debugger 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(errorer, 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), ("second", 2)], [("third", 3), ("fourth", 4)], debugger=None)