I want to make a program that prints how long it has been running. I tried this

import time
b = time.tick()
print b

Even if this did work it wouldnt do what I want it to do. I basically want it to tell me how long the program has been running every 10 seconds. How would I go about doing this?



You could do this:

while True:
    now = time.time()
    print now

The main problem with this approach is that the program can't do anything else during the sleeping period. You could potentially make a separate thread (look up threading if you don't know what this is) that would run this code while the rest of your program does its thing.

OR, you could do it using the after method from Tkinter, but this may pop up a window. Notice that this function works in milliseconds.

from Tkinter import *
import time

root = Tk()

def printtime():
    now = time.time()
    print now
    root.after(10000, printtime)