Exiting while loop by pressing enter without blocking. How can I improve this method?
This worked for me: import sys, select, os i = 0 while True: os.system(‘cls’ if os.name == ‘nt’ else ‘clear’) print “I’m doing stuff. Press Enter to stop me!” print i if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: line = raw_input() break i += 1 You only need to check for the stdin being input … Read more