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

32 lines
1.1 KiB
Python
Raw Normal View History

2022-10-19 11:31:45 +02:00
import aiosched
from raw_catch import child_raises
2022-10-19 11:31:45 +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:
2023-04-28 16:04:30 +02:00
async with aiosched.create_pool() as ctx:
2022-10-19 11:31:45 +02:00
before = aiosched.clock()
print("[main] Spawning children in first context")
for name, delay in children_outer:
await ctx.spawn(child_raises, name, delay)
2022-10-19 11:31:45 +02:00
print("[main] Children spawned")
2023-04-28 16:04:30 +02:00
async with aiosched.create_pool() as ctx2:
2022-10-19 11:31:45 +02:00
print("[main] Spawning children in second context")
for name, delay in children_inner:
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__":
aiosched.run(
main,
[("first", 1), ("second", 2)],
[("third", 3), ("fourth", 4)],
debugger=None,
)