27 lines
773 B
Python
27 lines
773 B
Python
import aiosched
|
|
|
|
|
|
|
|
async def child_raises(name: str, n: int):
|
|
before = aiosched.clock()
|
|
print(f"[child {name}] Sleeping for {n} seconds")
|
|
await aiosched.sleep(n)
|
|
print(f"[child {name}] Done! Slept for {aiosched.clock() - before:.2f} seconds, raising now!")
|
|
raise TypeError("waa")
|
|
|
|
|
|
async def main(n: int):
|
|
print("[main] Spawning child")
|
|
task = await aiosched.spawn(child_raises, "raise", n)
|
|
print("[main] Waiting for child")
|
|
before = aiosched.clock()
|
|
try:
|
|
await aiosched.wait(task)
|
|
except Exception as err:
|
|
print(f"[main] Child raised an exception -> {type(err).__name__}: {err}")
|
|
print(f"[main] Child exited in {aiosched.clock() - before:.2f} seconds")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
aiosched.run(main, 5)
|