2020-12-20 15:58:53 +01:00
|
|
|
import giambio
|
|
|
|
from debugger import Debugger
|
|
|
|
|
|
|
|
|
2021-04-22 11:30:35 +02:00
|
|
|
async def child(name: int):
|
|
|
|
print(f"[child {name}] Child spawned!! Sleeping for {name} seconds")
|
|
|
|
await giambio.sleep(name)
|
|
|
|
print(f"[child {name}] Had a nice nap!")
|
2020-12-20 15:58:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
start = giambio.clock()
|
|
|
|
try:
|
2021-10-09 14:35:41 +02:00
|
|
|
async with giambio.with_timeout(12) as pool:
|
2022-02-26 19:35:03 +01:00
|
|
|
await pool.spawn(child, 7) # This will complete
|
|
|
|
await giambio.sleep(2) # This will make the code below wait 2 seconds
|
2021-10-09 14:35:41 +02:00
|
|
|
await pool.spawn(child, 15) # This will not complete
|
2022-02-26 19:35:03 +01:00
|
|
|
await child(20) # Neither will this
|
|
|
|
await giambio.sleep(50) # Nor this
|
2020-12-20 15:58:53 +01:00
|
|
|
except giambio.exceptions.TooSlowError:
|
|
|
|
print("[main] One or more children have timed out!")
|
2021-07-22 11:13:08 +02:00
|
|
|
print(f"[main] Children execution complete in {giambio.clock() - start:.2f} seconds")
|
2020-12-20 15:58:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-02-04 11:56:15 +01:00
|
|
|
giambio.run(main, debugger=())
|