RuntimeError calling get_ports()
Hi. I meet a RuntimeError with the get_clients() Client method. Obviously it is not systematic at all and I was trying to make my program crash or find any other errors, stopping and starting JACK many times (when stopped, my client tries to connect to JACK every 500ms, on success it parse ports and connections).
File "/home/houston4444/RaySession/src/patchbay_daemon/patchbay_daemon.py", line 685, in get_all_ports_and_connections
port_name = port.name
^^^^^^^^^
File "/usr/lib/python3/dist-packages/jack.py", line 1841, in name
return _decode(_lib.jack_port_name(self._ptr))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/jack.py", line 82, in _decode
return _ffi.string(cdata).decode()
^^^^^^^^^^^^^^^^^^
RuntimeError: cannot use string() on <cdata 'char *' NULL>
Here is the part of my code where it happens:
#get all currents Jack ports and connections
for port in self.client.get_ports():
flags = jack._lib.jack_port_flags(port._ptr)
port_name = port.name
port_uuid = port.uuid
I also met a lot of problems (many functions never responding after server restart), but I saw that I was needing to close() the client when the server is stopped, and all problems disappear. Impossible to make my program crash or block.
Thanks for reporting this!
Your error message means that the function jack_port_name() has returned a NULL pointer.
This possibility is not mentioned in the documentation: https://jackaudio.org/api/group__PortFunctions.html#ga2abf1e9c3fa7d2afae6fd85a6e2ba843
Interestingly, in JACK1 this is not meant to happen:
https://github.com/jackaudio/jack1/blob/ab2e7363cacd0bf4b961c0466c13b0b4c1086ed9/libjack/port.c#L757-L761
(name is defined here: https://github.com/jackaudio/jack1/blob/ab2e7363cacd0bf4b961c0466c13b0b4c1086ed9/include/port.h#L102)
In JACK2, however, there are two legitimate ways for this to return NULL:
https://github.com/jackaudio/jack2/blob/43e1173e3060b2ebc9b6c54058464d5145afbf6e/common/JackAPI.cpp#L387-L400
As for why it is returning NULL in your case, I'm sorry, but I don't know.
This comes from the underlying JACK library, so you could ask there: https://jackaudio.org/community.html
BTW, I've seen that you are using non-public functions here:
flags = jack._lib.jack_port_flags(port._ptr)
Are you aware that you an access the flags using public properties, e.g. with port.is_input?
https://jackclient-python.readthedocs.io/en/0.5.5/api.html#jack.Port
Thanks for your search ! Not so strong however, the problem now seems to never happen since I close the client at server shutdown.
Are you aware that you an access the flags using public properties, e.g. with port.is_input?
Yes of course, the reason is that it was faster to code and to execute it this way because the patchbay lib I use (and develop) has API functions with flags argument. I could of course recreate the flags with the attributes or change my patchbay API (3 programs use it (mine)).
Are you aware that you an access the flags using public properties, e.g. with port.is_input?
I did not remember, but there is the control_voltage flag that I absolutely need, so call non-public function is needed in my case, no workaround possible (#136).