Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » How to handle exception in loop thread
How to handle exception in loop thread [message #1860015] Tue, 11 July 2023 02:09
Mike Riccio is currently offline Mike RiccioFriend
Messages: 1
Registered: July 2023
Junior Member
My client's network connection was interrupted due to a switch rebooting, and my paho mqtt client stopped working as a result. I start the loop with loop_start(), and I can see that the loop thread got an exception:

Jul 10 03:42:58 Exception in thread Thread-1 (_thread_main):
Jul 10 03:42:58 Traceback (most recent call last):
Jul 10 03:42:58   File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
Jul 10 03:42:58     self.run()
Jul 10 03:42:58   File "/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
Jul 10 03:42:58     self._target(*self._args, **self._kwargs)
Jul 10 03:42:58   File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 3591, in _thread_main
Jul 10 03:42:58     self.loop_forever(retry_first_connection=True)
Jul 10 03:42:58   File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
Jul 10 03:42:58     rc = self._loop(timeout)
Jul 10 03:42:58          ^^^^^^^^^^^^^^^^^^^
Jul 10 03:42:58   File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1164, in _loop
Jul 10 03:42:58     rc = self.loop_read()
Jul 10 03:42:58          ^^^^^^^^^^^^^^^^
Jul 10 03:42:58   File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 1556, in loop_read
Jul 10 03:42:58     rc = self._packet_read()
Jul 10 03:42:58          ^^^^^^^^^^^^^^^^^^^
Jul 10 03:42:58   File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 2370, in _packet_read
Jul 10 03:42:58     command = self._sock_recv(1)
Jul 10 03:42:58               ^^^^^^^^^^^^^^^^^^
Jul 10 03:42:58   File "/opt/homebrew/lib/python3.11/site-packages/paho/mqtt/client.py", line 640, in _sock_recv
Jul 10 03:42:58     return self._sock.recv(bufsize)
Jul 10 03:42:58            ^^^^^^^^^^^^^^^^^^^^^^^^


My code kept running after this, but it was no longer receiving any messages, so it was effectively broken at this point until I caught it.

How can I detect such an exception and force a reconnect attempt (or even abort the program which would trigger a restart)?

Thanks!
Previous Topic:attribute _on_pre_connect error
Next Topic:Losing subscriptions (RPi Python Paho)
Goto Forum:
  


Current Time: Fri May 03 11:40:33 GMT 2024

Powered by FUDForum. Page generated in 0.03514 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top