title: Accurate timer using python time [on the microseconds level]
body: <p>I want to create trigger that runs something every 500 ms, and it should be without drifting over time.
  I have this code running to show something in pyopengl</p>
  
  <pre><code>def __init__(self):
      ...
      self.t_on = time.clock()
      ...
  def display_gl(self):
      ...
      if (time.clock() - self.t_on) &gt;= 0.500:
          self.t_on = time.clock()
          #do things
      ...
  </code></pre>
  
  <p>the clock is drifting over time, I think that's because the <code>if</code> condition is catching the 500 ms moment after a little time.</p>
  
  <p>Is there any way to avoid this drifting issue?</p>
  
  <p><strong>Solved</strong>:<br>
  changed:</p>
  
  <pre><code>if (time.clock() - self.t_on) &gt;= 0.500:
      self.t_on = time.clock()
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>if (time.clock() - self.t_on) &gt;= 0.500:
      self.t_on =time.clock() - ((time.clock() - self.t_on) - 0.500)
  </code></pre>