rtmidi-python
rtmidi-python copied to clipboard
Crash if USB MIDI device is unplugged
-
Connect a USB MIDI IN device (example: USB MIDI keyboard)
-
Run the following code (see below)
-
Unplug the USB MIDI IN device
-
Crash ! or panic (
dmesg -wH
shows lots of[+0.000167] usb 1-1.4: urb status -32
... this doesn't seem to happen when rtmidi_midi is not running)
Is there a way to have no crash if a midi device is not available anymore (for example because the device is disconnected) ?
import time
import rtmidi_python as rtmidi
midi_in = rtmidi.MidiIn()
port = midi_in.ports[1] # this is Akai LPK25 on my system
midi_in.open_port(port)
print 'Opened MIDI: ' + port
i = 0
while True:
i += 1
time.sleep(0.5)
print i # a useful loop just to see when exactly it crashes