Print sync
- First let's see a few small and useless examples.
- In this example we use
sleepto imitate some external task we need to wait for and then we print out some text. - We do it sequentially. No async here.
The code
import time
def say(text, sec):
time.sleep(sec)
print(text)
def main():
start = time.monotonic()
say("First", 2)
say("Second", 1)
end = time.monotonic()
print(f"Elapsed: {end-start}")
main()
Output
First
Second
Elapsed: 3.0015416080132127
So it takes slightly more than 3 seconds to wait first for 2 and then for 1 second. No big surprise there.