2022-10-19 11:31:45 +02:00
|
|
|
import aiosched
|
2022-11-02 09:28:04 +01:00
|
|
|
from raw_catch import child_raises
|
2022-10-19 11:31:45 +02:00
|
|
|
from debugger import Debugger
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: This crashes 1 second later than it should be
|
2022-10-19 11:54:32 +02:00
|
|
|
async def main(
|
|
|
|
children_outer: list[tuple[str, int]], children_inner: list[tuple[str, int]]
|
|
|
|
):
|
2022-10-19 11:31:45 +02:00
|
|
|
try:
|
|
|
|
async with aiosched.with_context() as ctx:
|
|
|
|
before = aiosched.clock()
|
|
|
|
print("[main] Spawning children in first context")
|
|
|
|
for name, delay in children_outer:
|
2022-11-02 09:28:04 +01:00
|
|
|
await ctx.spawn(child_raises, name, delay)
|
2022-10-19 11:31:45 +02:00
|
|
|
print("[main] Children spawned")
|
|
|
|
async with aiosched.with_context() as ctx2:
|
|
|
|
print("[main] Spawning children in second context")
|
|
|
|
for name, delay in children_inner:
|
2022-11-02 09:28:04 +01:00
|
|
|
await ctx2.spawn(child_raises, name, delay)
|
2022-10-19 11:31:45 +02:00
|
|
|
print("[main] Children spawned")
|
|
|
|
except BaseException as err:
|
|
|
|
print(f"[main] Child raised an exception -> {type(err).__name__}: {err}")
|
|
|
|
print(f"[main] Children exited in {aiosched.clock() - before:.2f} seconds")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-10-19 11:54:32 +02:00
|
|
|
aiosched.run(
|
|
|
|
main,
|
|
|
|
[("first", 1), ("second", 2)],
|
|
|
|
[("third", 3), ("fourth", 4)],
|
|
|
|
debugger=None,
|
|
|
|
)
|