title: Limit loop frame rate
body: <p>As like of <a href="http://www.pygame.org/docs/ref/time.html#pygame.time.Clock.tick" rel="nofollow">pygame</a> i want to limit the frame rate of a loop. Pygame provide the <strong>pygame.time.Clock.tick()</strong> way to do it:</p>
  
  <blockquote>
    <p>If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling Clock.tick(40) once per frame, the program will never run at more than 40 frames per second.</p>
  </blockquote>
  
  <p>But how to do it natively in python ?</p>
  
  <p>To illustrate:</p>
  
  <pre><code>import time
  
  max_frames = 125 # 25*5
  current_frame = 1
  while current_frame &lt;= max_frames:
      print('frame', time.clock(), current_frame)
      current_frame += 1
  </code></pre>
  
  <p>produce:</p>
  
  <pre><code>('frame', 0.01, 1)
  ('frame', 0.01, 2)
  ('frame', 0.01, 3)
  [...]
  ('frame', 0.01, 124)
  ('frame', 0.01, 125)
  </code></pre>
  
  <p>I would like 25 frames per seconds, so</p>
  
  <pre><code>('frame', 0.01, 1)
  ('frame', 0.05, 2)
  ('frame', 0.08, 3)
  [...]
  ('frame', 4.98, 124)
  ('frame', 5.00, 125)
  </code></pre>