2020-11-28 13:04:27 +01:00
|
|
|
import giambio
|
|
|
|
from debugger import Debugger
|
|
|
|
|
|
|
|
|
|
|
|
async def child():
|
|
|
|
print("[child] Child spawned!! Sleeping for 2 seconds")
|
|
|
|
await giambio.sleep(2)
|
|
|
|
print("[child] Had a nice nap!")
|
2020-12-19 15:18:12 +01:00
|
|
|
raise TypeError("rip")
|
2020-11-28 13:04:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def child1():
|
2020-12-19 15:18:12 +01:00
|
|
|
print("[child 1] Child spawned!! Sleeping for 8 seconds")
|
|
|
|
await giambio.sleep(8)
|
2020-11-28 13:04:27 +01:00
|
|
|
print("[child 1] Had a nice nap!")
|
2020-12-19 15:18:12 +01:00
|
|
|
# raise TypeError("rip")
|
2020-11-28 13:04:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
start = giambio.clock()
|
|
|
|
try:
|
|
|
|
async with giambio.create_pool() as pool:
|
2021-06-08 17:21:59 +02:00
|
|
|
await pool.spawn(child)
|
|
|
|
await pool.spawn(child1)
|
2020-11-28 13:04:27 +01:00
|
|
|
print("[main] Children spawned, awaiting completion")
|
|
|
|
except Exception as error:
|
|
|
|
# Because exceptions just *work*!
|
|
|
|
print(f"[main] Exception from child caught! {repr(error)}")
|
2021-07-22 11:13:08 +02:00
|
|
|
print(f"[main] Children execution complete in {giambio.clock() - start:.2f} seconds")
|
2020-11-28 13:04:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-06-03 16:34:26 +02:00
|
|
|
giambio.run(main, debugger=Debugger())
|