Anomaly in time.clock()

Ross Ridge rridge at
Wed Mar 19 18:15:08 CET 2008

Godzilla  <godzillaismad at> wrote:
>But the time.clock() sometimes return a value of between -3.5 to -4.5
>seconds backward.

There are race conditions in your code.  In between the time you execute
"curTime = time.clock()" and calculate "curTime - self.timeStamp" in one
thread, the other thread can execute "self.timeStamp = time.clock()".
It's the only way your example program can print a negative "Actual
Elapsed Time" value.  The race condition seems unlikely, and it's hard
to explain how this could result in it printing a value in the range
of -3.5 to -4.5.  However, a race condition occuring between the two
evaluations of "curTime - self.timeStamp" is the only way your example
program could print a negative value.

					Ross Ridge

 l/  //	  Ross Ridge -- The Great HTMU
[oo][oo]  rridge at
 db  //	  

More information about the Python-list mailing list