NUT-Monitor: Add automatic reconnection mechanism for Qt5 and Qt6#3523
NUT-Monitor: Add automatic reconnection mechanism for Qt5 and Qt6#3523developersorli wants to merge 2 commits into
Conversation
- Add automatic reconnection when connection to NUT server is lost - Implement proper teardown of old PyNUTClient instances - Use specific exceptions (socket.error, ConnectionError, EOFError, OSError, PyNUT.PyNUTError) - Prevent multiple simultaneous reconnection attempts - Add 'was_online' flag to track connection state changes - Tested and confirmed working on both Qt5 and Qt6 Closes: networkupstools#3509 Signed-off-by: Programer <developer.sorli@gmail.com>
|
A ZIP file with standard source tarball and another tarball with pre-built docs for commit 4b9209f is temporarily available: NUT-tarballs-PR-3523.zip. |
|
✅ Build nut 2.8.5.4914-master completed (commit 572b34b736 by @developersorli)
|
…stools#3509, networkupstools#3523] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
|
With a real X11 environment (LightDM) the Py3Qt5 variant reconnected at least once, but most of the time it flooded "Broken pipe" notifications every couple of seconds that the data server was down and even after it went back up: The client was responsive, so I could open the menu or "Disconnect" and "Connect" it again with its UI buttons. Can't really say what the Py3Qt6 variant did, as I ran it from WSL2 (Ubuntu) rendering to a VcXsrv on its Windows host, and it stalled (maybe trying to post a notification which has nowhere to go, and waits for some response that would never come?) It did react to Ctrl+C on the console that I started it from, apparently breaking some loop and reacting to subsequent UI operations. Only then did the status bar update to also "Errno 32: Broken pipe" message (in one test the status bar remained "Connected to..." when it stalled, in another it went empty and remained that way until Ctrl+C). It did not auto-reconnect either after the data server restarted. |
…stools#3509, networkupstools#3523] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…tion modeled after PR networkupstools#3523 for Python3 siblings [networkupstools#3509] Co-Authored-By: Programer <developer.sorli@gmail.com> Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
|
Closing in favor of #3530 which includes (a rebase of) these commits and more, to add same feature to Py2Gtk2 variant and hopefully fix the issues logged above. Great thanks to @developersorli for the contribution! |

Summary
This PR adds an automatic reconnection mechanism to NUT-Monitor-py3qt5 and NUT-Monitor-py3qt6. When the connection to the NUT server is lost (e.g., after system suspend/resume, network interruption, or NUT server restart), the client will automatically attempt to reconnect.
Changes
Reconnection logic in
gui_updater.__update():New
__attempt_reconnect()method:__reconnect_attemptedflag - prevents multiple simultaneous attemptsProper exception handling:
socket.error- network/socket errorsConnectionError- Python 3 built-in connection errorsEOFError- end of file / connection closedOSError- operating system errorsPyNUT.PyNUTError- NUT protocol errorsProper teardown of old connection handler:
was_onlineflag - tracks connection state changesTesting
Qt5: ✅ Fully tested and confirmed working
Qt6: ✅ Fully tested and confirmed working
Files Modified
scripts/python/app/NUT-Monitor-py3qt5.inscripts/python/app/NUT-Monitor-py3qt6.inRelated Issues
Closes #3509
Notes for Reviewers
PyNUTClientinstance is properly cleaned up before reconnection