paho.mqtt.python icon indicating copy to clipboard operation
paho.mqtt.python copied to clipboard

Attempting to connect results in SystemError('_PyEval_EvalFrameDefault returned NULL without setting an exception')

Open ConorHartin opened this issue 2 years ago • 8 comments

I have two separate projects that I want to communicate using MQTT. I can start up one of them and have it connect a Paho MQTT client without errors, and even communicate with it on the command line. After that, when I try to call client.connect in the other repo, it results in the error shown above. There are sometimes when it doesn't fail on that, but then fails with the same message when attempting to subscribe to a topic. The version of paho I'm using is 1.6.1.

The specific line triggering the exception is line 649 of client.py, at the top of the function _sock_send: return self._sock.send(buf) If I put a debug breakpoint there can run "self._sock.send(buf)" in a console, it can return a value of 14 without problems, but then immediately afterward when I try to step into or over that line, the exception occurs.

ConorHartin avatar Oct 03 '23 16:10 ConorHartin

This seems like a host system python issue, and the internet says this is mysterious in general. You didn't explain what OS/version, what version of python, or post the full backtrace. Without that, I don't expect that anyone will be able to help you. (And if it is windows or non-current python, I won't be able to help...)

gdt avatar Oct 04 '23 13:10 gdt

This seems like a host system python issue, and the internet says this is mysterious in general. You didn't explain what OS/version, what version of python, or post the full backtrace. Without that, I don't expect that anyone will be able to help you. (And if it is windows or non-current python, I won't be able to help...)

It is indeed Windows. The version of Python is 3.10.

ConorHartin avatar Oct 04 '23 13:10 ConorHartin

Here is the traceback: Traceback (most recent call last): File "C:\Users<MyName><MyProjectFolder><my-project>\controllers\polling.py", line 432, in EthernetAdapter client.connect(other_repo_name if ENV == "production" else "localhost", 1883, 60), File "C:\Users<MyName>\AppData\Local\pypoetry\Cache\virtualenvs\api-ZOmfCtpL-py3.10\lib\site-packages\paho\mqtt\client.py", line 914, in connect return self.reconnect() File "C:\Users<MyName>\AppData\Local\pypoetry\Cache\virtualenvs\api-ZOmfCtpL-py3.10\lib\site-packages\paho\mqtt\client.py", line 1088, in reconnect return self._send_connect(self._keepalive) File "C:\Users<MyName>\AppData\Local\pypoetry\Cache\virtualenvs\api-ZOmfCtpL-py3.10\lib\site-packages\paho\mqtt\client.py", line 2819, in _send_connect return self._packet_queue(command, packet, 0, 0) File "C:\Users<MyName>\AppData\Local\pypoetry\Cache\virtualenvs\api-ZOmfCtpL-py3.10\lib\site-packages\paho\mqtt\client.py", line 3016, in _packet_queue return self.loop_write() File "C:\Users<MyName>\AppData\Local\pypoetry\Cache\virtualenvs\api-ZOmfCtpL-py3.10\lib\site-packages\paho\mqtt\client.py", line 1577, in loop_write rc = self._packet_write() SystemError: _PyEval_EvalFrameDefault returned NULL without setting an exception

ConorHartin avatar Oct 04 '23 19:10 ConorHartin

I don't know what to make of that. It could be a python bug. You might try installing 3.11 and starting out with a fresh venv.

gdt avatar Oct 04 '23 22:10 gdt

I don't know what to make of that. It could be a python bug. You might try installing 3.11 and starting out with a fresh venv.

I tried that and got the error described here, for which the recommended solution is... downgrade the version of Python: https://stackoverflow.com/questions/64427613/error-loading-psycopg2-module-dll-load-failed-while-importing-psycopg-the-spe

ConorHartin avatar Oct 06 '23 14:10 ConorHartin

I'm out of ideas -- but as I said, I have chosen to avoid understanding Windows....

gdt avatar Oct 06 '23 15:10 gdt

It seemed to pop up in debug mode, but only in one out of 2 different repos calling the same function with the exact same arguments. Disabling breakpoints prior to connecting/subscribing seemed to fix it for the one that was failing.

ConorHartin avatar Oct 24 '23 16:10 ConorHartin

Do you have more details on when that happen ? It's Windows with Python 3.10.N ? Are you using SSL connection ? Websocket ? This only happen while debugging is enabled, which debugger ?

This seems more a Python/Debugger issue than paho bug. I don't think pure-Python code could be the cause of such error, I believe it require at least writing C extension.

PierreF avatar Jan 07 '24 17:01 PierreF