0

So, a while true loop that only passes, freezes the window. But a while true loop that checks the pool of events for a Quit event won't freeze. Why is that? checking the events take enough time to prevent the program from overloading? What is going on inside the hood?

Loop that freezes the Pygame window:

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

while True:
    pass

Loop that won't freeze the Pygame window:

import pygame

pygame.init()

screen = pygame.display.set_mode((800, 600))

running = True
while running:
   for e in pygame.event.get():
       if e.type == pygame.QUIT:
           running = False

So if both are running infinitely (The second one virtually, supposed that the QUIT event is never called), why the first one consumes so many resources that it overloads it an freezes the window, but the second one "behaves" and doesn't overload it, even if the exit condition of the loop is not called? Is there some waiting time in the pygame.event.get() function?

I tried looking for info on Google but I got lost in subprocesses, etc.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Adrian
  • 11
  • 1
  • 1
    "overloads it an freezes the window" -- that's not what's happening. The first case doesn't process events, which is what makes the GUI work. – Dan Mašek Dec 04 '22 at 11:50

0 Answers0