Time.sleep() is not working with as it should

Problem description:
time.sleep() stacks immediately with the print statements and the order of the code is ignored in this. Code used is shown below:

import time
print("Processing" , sep = "" , end = "")
time.sleep(2)
print("." , sep = "" , end = "")
time.sleep(2)
print("." , sep = "" , end = "")
time.sleep(2)
print("." , sep = "" , end = "")

Expected behavior:
“processing” - 2 second interval - “.” - 2 second interval - “.” - 2 second interval - “.”

Actual behavior:
6 second wait - “processing…”

Steps to reproduce:
create a print statement with an end=“” clause at the end, use time.sleep() and then print another statement

Bug appears at this link:
https://replit.com/@RobertoSilvaPer/Bug-report#main.py

Browser/OS/Device:
Microsoft Edge/Windows 11/ Dell OptiPlex 3280 AIO x64-based PC

Hi @RobertoSilvaPer , welcome to the forums!
Could you add back the line import time?
Thanks!

@NateDhaliwal:

Second, @RobertoSilvaPer:

Since you’re printing without a newline, Python waits until there’s either a newline or it’s explicitly told to flush the text to the screen.
You could quickly fix this by adding flush=True too all you print statements without a newline at the end.

4 Likes