2020-11-13 10:44:47 +01:00
|
|
|
import giambio
|
|
|
|
|
|
|
|
|
2020-11-13 13:01:40 +01:00
|
|
|
async def child(sleep: int, ident: int):
|
|
|
|
start = giambio.clock() # This returns the current time from giambio's perspective
|
|
|
|
print(f"[child {ident}] Gonna sleep for {sleep} seconds!")
|
2020-11-13 10:44:47 +01:00
|
|
|
await giambio.sleep(sleep)
|
|
|
|
end = giambio.clock() - start
|
2020-11-13 13:01:40 +01:00
|
|
|
print(f"[child {ident}] I woke up! Slept for {end} seconds")
|
2020-11-13 10:44:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
2020-11-13 13:01:40 +01:00
|
|
|
print("[parent] Spawning children")
|
|
|
|
task = giambio.spawn(child, 1, 1) # We spawn a child task
|
|
|
|
task2 = giambio.spawn(child, 2, 2) # and why not? another one!
|
2020-11-13 10:44:47 +01:00
|
|
|
start = giambio.clock()
|
2020-11-13 13:01:40 +01:00
|
|
|
print("[parent] Children spawned, awaiting completion")
|
2020-11-13 10:44:47 +01:00
|
|
|
await task.join()
|
2020-11-13 13:01:40 +01:00
|
|
|
await task2.join()
|
2020-11-13 10:44:47 +01:00
|
|
|
end = giambio.clock() - start
|
2020-11-13 13:01:40 +01:00
|
|
|
print(f"[parent] Execution terminated in {end} seconds")
|
2020-11-13 10:44:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-11-13 13:01:40 +01:00
|
|
|
giambio.run(main) # Start the async context
|