This repository has been archived on 2023-05-12. You can view files and clone it, but cannot push or open issues or pull requests.
aiosched/tests/nested_context_catch_outer.py

34 lines
1.1 KiB
Python

import aiosched
from raw_catch import child_raises
# TODO: This crashes 1 second later than it should be
async def main(
children_outer: list[tuple[str, int]], children_inner: list[tuple[str, int]]
):
try:
async with aiosched.with_context() as ctx:
before = aiosched.clock()
print("[main] Spawning children in first context")
for name, delay in children_outer:
await ctx.spawn(child_raises, name, delay)
print("[main] Children spawned")
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")
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__":
aiosched.run(
main,
[("first", 1), ("second", 2)],
[("third", 3), ("fourth", 4)],
debugger=None,
)