Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1579

Python • Python module hangs, keeping script from crashing

$
0
0
I'm getting an exception in a module my python script uses but which I have not written. It seems that my script ends up hanging when the exception happens. If my script exited at that point, then it could be restarted automatically. I suspect the relevant part of my script is this:

Code:

mqttclient.loop_start()
What alternatives do I have to trap the error below? Should I use a different approach to keeping the MQTT connection alive?

Code:

Exception in thread Thread-1 (_thread_main):Traceback (most recent call last):  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner    self.run()  File "/usr/lib/python3.11/threading.py", line 975, in run    self._target(*self._args, **self._kwargs)  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 3591, in _thread_main    self.loop_forever(retry_first_connection=True)  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1756, in loop_forever    rc = self._loop(timeout)         ^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1164, in _loop    rc = self.loop_read()         ^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 1556, in loop_read    rc = self._packet_read()         ^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 2389, in _packet_read    byte = self._sock_recv(1)           ^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/paho/mqtt/client.py", line 640, in _sock_recv    return self._sock.recv(bufsize)           ^^^^^^^^^^^^^^^'NoneType' object has no attribute 'recv'

Statistics: Posted by tpyo kingg — Sat Aug 30, 2025 9:01 am



Viewing all articles
Browse latest Browse all 1579

Trending Articles