#!/usr/bin/python import sys, os, select, time i = 0 def getInput(): input = '' while len(select.select([sys.stdin.fileno()], [], [], 0.0)[0])>0: input += os.read(sys.stdin.fileno(), 4096) return input def doWork(): global i time.sleep(0.5) i += 1 if __name__=='__main__': input = '' while not input: doWork() input = getInput() print "got user input: %r" % input print "did %d units of work" % i