0

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?

Thanks.

Rysin

2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by aot
0

You could do this:

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

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)
    
printtime()
root.mainloop()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.