So I have a script that will continuously read from a sensor, print a carriage return and then the sensor value. It does this until raw_input()
finishes blocking (enter pressed).
However, when I run it, instead of an increasing number, I see blank space. When I press enter, one number is printed and then the program exits. If \r
is replaced by \n
, the program runs as it should, printing out the "sensor" value (i = i + 1
is a placeholder for the reading of the sensor), but instead of reusing the same line it prints it on a new line.
Why does it not work with \r
?
Here is the full code:
from threading import Thread
from time import sleep
import sys
running = True
def loop():
i = 0
while running:
sys.stdout.write("\r" + str(i))
i = i+1
sleep(0.1)
thread = Thread(target=loop)
thread.start()
raw_input()
running = False
thread.join()