I have a pygame code which I wanted to be executed for only X seconds, I tried
sleep(10)
pygame.quit()
It just continues to run.
I have a pygame code which I wanted to be executed for only X seconds, I tried
sleep(10)
pygame.quit()
It just continues to run.
Change
sleep(10)
pygame.quit()
to
from sys import exit
sleep(10)
pygame.quit()
exit()
Though the program could exit a few milliseconds off your actual time, you could try to use the method defined in this answer and constantly check by resetting time.time()
repeatedly in a while
loop which should be fairly easy since you are using PyGame after all:
import time
start_time = time.time()
while True:
if time.time() - start_time() >= 10:
pygame.quit()