title: pygame.display.update() causing periodic lag spikes
body: <p>I made a simple program with Pygame that was basically a scrolling background and noticed periodic lag spikes. After messing with the code for a long time, I found out that calls to pygame.display.update() would sometimes take a lot longer to execute.</p>
  
  <p>To really strip down and replicate the problem, I wrote the following piece of code:</p>
  
  <pre><code>import pygame
  import sys
  import time
  
  FRAME_RATE = 30
  
  # don't mind the screen and time_passed variables; they aren't used in this script
  
  def run_game():
      pygame.init()
      clock = pygame.time.Clock()
      screen = pygame.display.set_mode((500, 500))
      prev_spike = 0
      time_passed = 0
      while 1:
          start = time.clock()
          pygame.display.update()
          timenow = time.clock()
          time_spent = timenow - start
          if time_spent &gt; 0.01:
              print time_spent 
              if prev_spike:
                  print "Last spike was: {} seconds ago".format(timenow - prev_spike)
              prev_spike = timenow
          time_passed = clock.tick(FRAME_RATE)
  
  if __name__ == "__main__":
      run_game()
  </code></pre>
  
  <p>A snippet of output at that framerate:</p>
  
  <pre><code>0.0258948412828
  Last spike was: 1.01579813191 seconds ago
  0.0186809297657
  Last spike was: 0.982841934526 seconds ago
  0.0225958783907
  Last spike was: 2.01697784257 seconds ago
  0.0145269648427
  Last spike was: 1.01603407404 seconds ago
  0.0186094554386
  Last spike was: 2.01713885195 seconds ago
  0.0283046020628
  Last spike was: 1.03270104172 seconds ago
  0.0223322687757
  Last spike was: 1.01709735072 seconds ago
  0.0152536205013
  Last spike was: 1.01601639759 seconds ago
  </code></pre>
  
  <p>I've really no clue what's going on, and would really love some insight.</p>
  
  <p>Some more details:</p>
  
  <p>A snippet of the output when printing the time_spent in every loop iteration (instead of only when it was > 0.01):</p>
  
  <pre><code>0.000204431946257
  0.000242090462673
  0.000207890381438
  0.000272447838151
  0.000230178074828
  0.0357667523718          &lt;-- update taking two orders of magnitude longer than normal
  0.000293582719813
  0.000343153624075
  0.000287818661178
  0.000249391603611
  </code></pre>
  
  <p>When run at 60 FPS, the interval between each spike almost always be 1 second, very rarely 2 seconds (and the spikes would last about twice as long). At lower frame rates, the interval between spikes would start to vary more, but would always be close to a whole number in value.</p>
  
  <p>I tried running the script on another computer, but the problem wasn't replicated; the execution time on pygame.display.update() was reasonably quick and consistent. However, when I ran my original program on that machine, the one-second-interval lag spikes remained (I'll probably look for other machines to test on...)</p>
  
  <p>Both machines that I tested on ran Windows 7.</p>
  
  <p>EDIT:</p>
  
  <p>I grabbed a few random games hosted on the Pygame website and I'm getting similar behaviour - calls to <code>pygame.display.update</code> (or <code>flip</code>) periodically take between 10 - 40 ms, whereas they normally take less than 2 ms. </p>
  
  <p>Nobody else seems to be having this problem (or complaining about, at it least. That could be because most games run on less than 30 FPS where this issue isn't too noticeable), so there's likely something off with my environment. I did (kinda) reproduce the issue on a second machine though (as described above), so I'd rather not ignore the problem and hope end users don't experience it...</p>