title: pywin32 win32gui GetPixel fails predictably near 10,000th call
body: <p>When running the following block of code, GetPixel starts throwing errors at around the 10,000th call every time. If I put the code in a try-except statement and all calls after the initial faliure will fail. The only way to recover is to terminate the script and run it again. I have tried putting a brief sleep between the calls. I have tried triggering garbage collection between the calls. I have tried running the script from the IDE and as a standalone process. Any ideas? Even running the script and reporting if/when it fails would help.</p>
  
  <pre><code>import gc
  import os
  import time
  import win32api, win32con, win32gui
  import sys
  import win32com.client
  
  terms = 0
  
  def get_pixel_colour(i_x, i_y):
      i_desktop_window_id = win32gui.GetDesktopWindow()
      i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id)
      long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y)
      i_colour = int(long_colour)
      return (i_colour &amp; 0xff), ((i_colour &gt;&gt; 8) &amp; 0xff), ((i_colour &gt;&gt; 16) &amp; 0xff)
  
  
  for x in range (0, 1000000):
      colour = get_pixel_colour(500, 500)
      terms = terms + 1
      print terms
  </code></pre>
  
  <p>The error that is returned is</p>
  
  <pre><code>error: (0, 'GetPixel', 'No error message is available')
  </code></pre>