Skip to content

Commit 5758874

Browse files
committed
scripts/python/app/NUT-Monitor-py3qt{5,6}.in: fix "Broken pipe" and possible stall in reconnection attempts [#3509]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent 1b5e77c commit 5758874

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

scripts/python/app/NUT-Monitor-py3qt5.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,17 @@ class gui_updater :
10471047
# Stop the current timer
10481048
self.__timer.stop()
10491049

1050+
# Close the socket to avoid "Broken pipe" in subsequent calls if any
1051+
try:
1052+
self.__parent_class._interface__ups_handler._PyNUTClient__srv_handler.close()
1053+
except Exception:
1054+
pass
1055+
10501056
# Schedule reconnection attempt after 2 seconds
10511057
QTimer.singleShot(2000, self.__attempt_reconnect)
1058+
elif self.__reconnect_attempted:
1059+
# Reconnection already in progress, just ignore this update
1060+
pass
10521061
else:
10531062
self.__parent_class.gui_status_message( _("Error from '{0}' ({1})").format( ups, sys.exc_info()[1] ) )
10541063
self.__parent_class.gui_status_notification( _("Error from '{0}'\n{1}").format( ups, sys.exc_info()[1] ), "warning.png" )
@@ -1129,6 +1138,7 @@ class gui_updater :
11291138
self.__timer.start(1000)
11301139

11311140
def stop_thread( self ) :
1141+
self.__stop_thread = True
11321142
if hasattr(self, '_gui_updater__timer'):
11331143
self.__timer.stop()
11341144

scripts/python/app/NUT-Monitor-py3qt6.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,17 @@ class gui_updater :
10701070
# Stop the current timer
10711071
self.__timer.stop()
10721072

1073+
# Close the socket to avoid "Broken pipe" in subsequent calls if any
1074+
try:
1075+
self.__parent_class._interface__ups_handler._PyNUTClient__srv_handler.close()
1076+
except Exception:
1077+
pass
1078+
10731079
# Schedule reconnection attempt after 2 seconds
10741080
QTimer.singleShot(2000, self.__attempt_reconnect)
1081+
elif self.__reconnect_attempted:
1082+
# Reconnection already in progress, just ignore this update
1083+
pass
10751084
else:
10761085
self.__parent_class._interface__online = None
10771086
self.__parent_class.change_status_icon( "warning", blink=True )
@@ -1154,9 +1163,9 @@ class gui_updater :
11541163
self.__timer.start(1000)
11551164

11561165
def stop_thread( self ) :
1166+
self.__stop_thread = True
11571167
if hasattr(self, '_gui_updater__timer'):
11581168
self.__timer.stop()
1159-
self.__stop_thread = True
11601169

11611170

11621171
#-----------------------------------------------------------------------

0 commit comments

Comments
 (0)