Python timer clocking
Question: I am thinking to implement a function like below:

    
    
    timeout = 60 second
    timer = 0
    while (timer not reach timeout):
        do somthing
        if another thing happened:
             reset timer to 0
    

My question is how to implement the timer stuff? Multiple thread or a
particular lib?

I hope the solution is based on the python built-in lib rather than some
third-part fancy package.

Thanks in advance.

PS: A clue should be fine, you don't need to give the whole solution.


Answer: I don't think you need threads for what you have described.

    
    
    import time
    
    timeout = 60
    timer = time.clock()
    while timer + timeout < time.clock():
        do somthing
        if another thing happened:
            timer = time.clock()
    

Here, you check every iteration.

The only reason you would need a thread is if you wanted to stop _in the
middle_ of an iteration if something was taking too long.

