import _thread import time import sys import os class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): try: self.impl = _GetchWindows() except ImportError: self.impl = _GetchUnix() def __call__(self): return self.impl() class _GetchUnix: def __init__(self): import sys, tty, termios def __call__(self): import sys, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch class _GetchWindows: def __init__(self): import msvcrt def __call__(self): import msvcrt msvcrt_char = msvcrt.getch() return msvcrt_char.decode("utf-8") def input_thread(done): getch = _Getch() while getch.impl() != 'q': pass done[0] = True def main(): done = [False] _thread.start_new_thread(input_thread, (done,)) i = 0 while not done[0]: i+=1 #do your things here print("\r"+['\\','|','/','-'][i&3]+" press q to quit...", end="") time.sleep(.1) print() main()