2020-11-28 13:04:27 +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-11-28 13:04:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
start = giambio.clock()
|
|
|
|
async with giambio.create_pool() as pool:
|
2022-05-14 11:19:55 +02:00
|
|
|
# await pool.spawn(child, 1) # If you comment this line, the pool will exit immediately!
|
2021-06-08 17:21:59 +02:00
|
|
|
task = await pool.spawn(child, 2)
|
2020-11-28 13:04:27 +01:00
|
|
|
print("[main] Children spawned, awaiting completion")
|
2022-05-14 11:19:55 +02:00
|
|
|
await task.cancel()
|
|
|
|
print("[main] Second child cancelled")
|
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-08-28 23:26:24 +02:00
|
|
|
giambio.run(main, debugger=())
|