0

I'd like to create a stopwatch of-sorts that records the duration elapsed from a specific moment in time. I would then save it to a database. When I close the application and then reload the application I'd like to be able to see the time elapsed since the specific moment in time the timer was initiated. I'd also like to eventually be able to see days elapsed as well. What would be the best way of going about this?

WewLad
  • 717
  • 2
  • 11
  • 22

2 Answers2

0

You can put your timer code in thread, which will work as deamon , and record the time:

class TimeThread(threading.Thread): 
    stop = 0
    def __init__(self):
        threading.Thread.__init__(self)     

    def run(self):
        # here your code for timer
        #you can put some condition to insert it to db!

    def stop(self):
        self.__stop = True
        print 'in stop'
        self.stop = 1

to start this thread, in background as deamon, do this:

f_thread = TimeThread()
f_thread.start()    
U.Swap
  • 1,921
  • 4
  • 23
  • 41
0

Write the start time in a file.

Or, don't even bother writing the time in the file, just touch the file and use its modification time. For that, see: Implement touch using Python?

Community
  • 1
  • 1
Nick Matteo
  • 4,453
  • 1
  • 24
  • 35