pymqi connection calls fail in subprocesses on osx *and* the exception kills the python shell

50 Views Asked by At

On Linux, the following pairs of commands both work:

$ python -c "import pymqi; pymqi.connect('QM1', 'DEV.APP.SVRCONN', 'localhost(1414)', user='xxx', password='xxx')"  # command 1
$ bash -c "python -c \"import pymqi; pymqi.connect('QM1', 'DEV.APP.SVRCONN', 'localhost(1414)', user='xxx', password='xxx')\""  # command 2

On OSX, the first one succeeds and the second fails with this output:

TENDTraceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages/pymqi/__init__.py", line 3214, in connect
    qmgr.connect_tcp_client(queue_manager or '', CD(), channel, conn_info, user, password)
  File "/Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages/pymqi/__init__.py", line 1772, in connect_tcp_client
    self.connect_with_options(name, **kwargs)
  File "/Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages/pymqi/__init__.py", line 1747, in connect_with_options
    raise MQMIError(rv[1], rv[2])
pymqi.MQMIError: MQI Error. Comp: 2, Reason 2009: FAILED: MQRC_CONNECTION_BROKEN

(Note that weird TEND prefix before Traceback. Weird!)

Not only that, but if I just run bash -c python and then do import pymqi; pymqi.connect('QM1', 'DEV.APP.SVRCONN', 'localhost(1414)', user='xxx', password='xxx') in the python shell, I get the same exception and the Python process itself exits.

This does not seem to happen when running the sample programs in /opt/mqm/samp/bin/.

I assume this has something to do with some OSX thing, but … what? and is there a workaround?

EDIT: This is not related to DYLD_LIBRARY_PATH. There is no nested build-time error:

% bash -c "pipenv run pip install pymqi"
Requirement already satisfied: pymqi in /Users/wolfson/.local/share/virtualenvs/xxx-xWWWLtqs/lib/python3.11/site-packages (1.12.10)

And it is (obviously) possible to import pymqi.pymqe in the nested shell.

1

There are 1 best solutions below

5
chughts On

This is due to the System Integrity Protection feature in macOS. Certain executables (including shell scripts) don't inherit DYLD_LIBRARY_PATH.

To see this is action:

  1. Open a terminal
  2. Run echo $DYLD_LIBRARY_PATH
  3. Run bash
  4. Run echo $DYLD_LIBRARY_PATH

DYLD_LIBRARY_PATH needs to be set to pick up the MQ client runtime dynamic libraries that by default are in /opt/mqm/lib64