views:

207

answers:

1

Hi,

I see time.clock() on Windows 'starts' a timer when called for the first time, and returns elasped time since the first call for calls after that. I read that the only way to restart the clock is to start a new process.

Is starting and killing threads supposed to restart the time.clock() as well? It doesn't seem to be working right now. If not, is the only solution to re-launch the entire executable?

+3  A: 

A thread is not a process, so, no. (As a minor point, you can't kill a thread in Python, you can only ask it to exit. Killing threads through other means, where such means even exist, is likely to leave Python in a bad state.)

The question is why you want to reset the timer, and also why you are using time.clock(). If you care about the elapsed time between two points at such a high granularity that time.time() is not suitable, you'll just have to subtract the first point from the second point. No resetting required. I would recommend just using time.time() unless you really care about that tiny bit of difference in granularity, as time.time() works the same way on all platforms, contrary to time.clock().

Thomas Wouters
i'm trying to measure response between serial communications, so yes, i would want to use time.clock(). I'll go ahead and subtract the two values to find the difference. Thanks for the answer
PPTim