title: Simple script with infinite loop slows down the computer
body: <pre><code>import win32gui
  import pyautogui
  import winsound
  
  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)
  
  def is_top_free(x, y):
      if all(i in range(35,46) for i in get_pixel_colour(x+258, y+108) and get_pixel_colour(x+283, y+108) and get_pixel_colour(x+283, y+139) and get_pixel_colour(x+258, y+139)) and all(i in range(80, 90) for i in get_pixel_colour(x+264, y+131)):
          return True
      else:
          return False
  
  def is_bottom_free(x, y):
      if all(i in range(35, 46) for i in get_pixel_colour(x+256, y+788) and get_pixel_colour(x+286, y+788) and get_pixel_colour(x+256, y+820) and get_pixel_colour(x+286, y+820)) and all(i in range(80, 90) for i in get_pixel_colour(x+264, y+808)):
          return True
      else:
          return False
  
  def get_top_seat(x, y):
      current = pyautogui.position()
      pyautogui.click(x+267, y+126)
      pyautogui.moveTo(current[0], current[1])
      winsound.Beep(500, 500)
  
  def get_bottom_seat(x, y):
      current = pyautogui.position()
      pyautogui.click(x+267, y+802)
      pyautogui.moveTo(current[0], current[1])
      winsound.Beep(500, 500)
  
  def callback(hwnd, extra):
      rect = win32gui.GetWindowRect(hwnd)
      x = rect[0]
      y = rect[1]
      w = rect[2] - x
      h = rect[3] - y
      if win32gui.GetWindowText(hwnd) in accounts:
          if is_top_free(x, y):
              get_top_seat(x, y)
          elif is_bottom_free(x, y):
              get_bottom_seat(x,y)
  
  accounts = ['3948700830', '3949029392', '3949074503', '3949131493', '3949174547', '3949206036']
  
  try:
      while True:
          win32gui.EnumWindows(callback, None)
  except KeyboardInterrupt:
      print('End')
  </code></pre>
  
  <p>This script looks for a button and clicks it when possible. </p>
  
  <p>Computer works slower and slower while running this script. I guess some variables are being overwritten without deleting from memory. I tried adding some sleep to the loop but it didn't solve the problem - it slows down slower but still regularly. Do you have any ideas what might cause it?</p>