Skip to content

Commit

Permalink
fix: (no)gil/except declarations on MIDI in callback and sendMessage (#…
Browse files Browse the repository at this point in the history
…185)

GIL is acquired in any case for MIDI in callback and `sendMessage`, since Cython needs to check C++ call for exceptions

Also remove wrong statement about the GIL being released in docstring for `sendMessage`

Lastly, suppress related Cython performance hints

Signed-off-by: Christopher Arndt <[email protected]>
  • Loading branch information
SpotlightKid authored Oct 23, 2023
1 parent e9661a4 commit c0b9381
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/_rtmidi.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cython: embedsignature = True
# cython: language_level = 3
# cython: show_performance_hints = False
# distutils: language = c++
#
# rtmidi.pyx
Expand Down Expand Up @@ -202,13 +203,13 @@ cdef extern from "RtMidi.h":
cdef cppclass RtMidiOut(RtMidi):
Api RtMidiOut(Api rtapi, string clientName) except +
Api getCurrentApi()
void sendMessage(vector[unsigned char] *message) except * nogil
void sendMessage(vector[unsigned char] *message) except *


# internal functions

cdef void _cb_func(double delta_time, vector[unsigned char] *msg_v,
void *cb_info) with gil:
void *cb_info) except * with gil:
"""Wrapper for a Python callback function for MIDI input."""
func, data = (<object> cb_info)
message = [msg_v.at(i) for i in range(msg_v.size())]
Expand Down Expand Up @@ -1086,9 +1087,7 @@ cdef class MidiOut(MidiBase):
must be a start-of-sysex status byte, i.e. 0xF0.
.. note:: with some backend APIs (notably ```WINDOWS_MM``) this function
blocks until the whole message is sent. While sending the message
the global interpreter lock is released, so multiple Python threads
can send messages using *different* MidiOut instances concurrently.
blocks until the whole message is sent.
Exceptions:
Expand All @@ -1109,5 +1108,4 @@ cdef class MidiOut(MidiBase):
for c in message:
msg_v.push_back(c)

with nogil:
self.thisptr.sendMessage(&msg_v)
self.thisptr.sendMessage(&msg_v)

0 comments on commit c0b9381

Please sign in to comment.