I think this is a bug in Pygame, but there was nothing in the tracker seeming to match. I can replicate the issue with PyGame 1.9.4.post1.
The cause of the issue is calling pygame.midi.Output()
, I played around with a few different calls to this, specifying different parameters gives different errors - sometimes on call, but other times on shutdown.
It's a workaround, not a solution - but do you actually need to call this function? Basic MIDI functionality seems to work without it. The code below plays a MIDI file, then exits cleanly.
import sys
import pygame
import pygame.midi
pygame.init()
pygame.midi.init()
pygame.mixer.init()
midi_file = "popcorn.mid"
pygame.mixer.music.load( midi_file )
pygame.mixer.music.play()
device = pygame.midi.get_default_output_id()
device_info = pygame.midi.get_device_info( device )
print( "MIDI Device: " + str( device ) )
print( "Device Info: " + str( device_info ) )
#player = pygame.midi.Output( device, buffer_size=4096 )
clock = pygame.time.Clock()
while pygame.mixer.music.get_busy():
pygame.time.delay( 1500 )
print("", end='')
sys.stdout.flush() # just ensure the tick-mark is printed in-time
pygame.mixer.music.stop()
pygame.quit()
Maybe a later version of PyGame - perhaps even the (upcoming?) SDL2 version.