I'm writing a program to plays chess against the computer. I have a Pygame window that shows the chessboard and lets you select your move. Once you have played your move the engine starts calculating the moves' tree, to find the best move. When it has finished it replays with its move. The problem is that while the engine is "thinking" the Pygame window is not updated for a while (it can be a lot, even a minute or more). And the OS prompts the message "not responding" on the window after 5 seconds of inactivity. Here is a Minimum Reproducible Example:
import pygame
from time import sleep
def engine_play():
# Here the engine searches for the best move for some time
for _ in range(1000000000):
a = 1+1
pygame.init()
clock = pygame.time.Clock()
clock.tick(60)
WIN = pygame.display.set_mode((500, 500))
engine_play()
# When the engine stops searching we get the events
pygame.event.get()
When the engine stops and pygame.event.get()
is called, the message disappears and everything is fine.
The main problem is that if you click on the window during this time Windows warns you that the program is not responding and asks you if you want to close it or to wait.
Does anyone know how to fix this? Thanks in advance!