1

Pygame was working perfectly last night, now the pygame.init() function is taking ~ 40 seconds to finish compared to being instant before.

import pygame
import time
start = time.time()
pygame.init()
print(f"Runtime: {time.time() - start}")

Console results:

"C:\Program Files\Python39\python.exe" "D:/Google Drive/CompSci/proj/Alien Invasion/test.py"
pygame 2.0.1 (SDL 2.0.14, Python 3.9.0)
Hello from the pygame community. https://www.pygame.org/contribute.html
Runtime: 40.15961766242981

Where normally the runtime should be almost instant...

I have exclusions in Windows Defender for all related folders: Windows Defender exlusions

Rebeljah
  • 35
  • 4
  • 1
    [This GitHub issue](https://github.com/pygame/pygame/issues/1573) looks like it has some good troubleshooting steps. Did you recently change anything related to display, input or audio hardware? – Random Davis Feb 22 '21 at 18:02
  • Ok I was able to narrow it down to pg.joystick.init(). After unplugging and plugging back in my keyboard the loading problem goes away... – Rebeljah Feb 22 '21 at 18:29
  • Okay I'll post the resolution as an answer so you can upvote and/or accept it if you want. – Random Davis Feb 22 '21 at 18:46

1 Answers1

9

According to this GitHub issue, a troubleshooting step is to do all of the inits separately, like:

pygame.display.init()
pygame.mixer.pre_init(frequency=44100, size=-16, channels=2, buffersize=512, 
                      allowedchanges=pygame.AUDIO_ALLOW_ANY_CHANGE)
pygame.mixer.init()
pygame.joystick.init()

This will make it obvious which one is slowing things down. In OP's case it was joystick.init() casuing the slowness, which was solved by disconnecting and re-connecting the keyboard.

Random Davis
  • 6,662
  • 4
  • 14
  • 24