Your programm getprogram gets stuck after closing, bec. u because you only stop the enginesengine, and not the python programmPython program.
uYou need to exit the system
like as follows:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()