Sync sleep
- The same, but now we also print progress in the say function. Still sequential.
examples/async/sleep_sync.py
import time def say(wid, sec): start = time.monotonic() print(f"Starting {wid} that will take {sec}s") time.sleep(sec) end = time.monotonic() print(f"Finishing {wid} in {end-start}s") def main(): start = time.monotonic() say("First", 2), say("Second", 1) end = time.monotonic() print(f"Elapsed: {end-start}") main()
Starting First that will take 2s Finishing First in 2.002233584993519s Starting Second that will take 1s Finishing Second in 1.0011189789511263s Elapsed: 3.003522119950503