#!/usr/bin/python import time import sys import signal def main(): start = time.time() # Trap ctrl+c signal.signal(signal.SIGINT, sig_handle) while 1: now = time.time() elapsed = "%.2f" % (now - start) print format_time(elapsed), sys.stdout.flush() # Rest for a while time.sleep(.123) # Format the time string to output (add "minutes" and "seconds") def format_time(seconds): seconds_str = seconds; seconds_flt = float(seconds) # there are minutes if seconds_flt >= 60: minutes = int(seconds_flt / 60) seconds_str = seconds_flt % 60 ret_str = str(minutes) + " minutes and " + str(seconds_str) + " seconds" # Only seconds else: ret_str = str(seconds_str) + " seconds" ret = "\b" * 100 + ret_str return ret # Handle the CTRL+C if a user presses it (don't spit out 100000 python errors def sig_handle(signal,frame): sys.exit(0) if __name__ == '__main__': main()