I'm trying to use the sleep function to have a delay between iterations in a loop but the loop executes all at once without delays.
from time import sleep
for i in range(5):
print (i)
sleep(0.5)
I tried doing it without a loop and the same problem, prints all the text instantly:
from time import sleep
print('hi')
sleep(2)
print('hi')
sleep(2)
print('hi')
sleep(2)
Edit: The issue is indeed output buffering. Adding sys.stdout.flush() after every print line fixed the issue.