Skip to content

Commit db05b67

Browse files
committed
scripts/python/app/NUT-Monitor-*.in: refactor old_handler teardown with new graceful and harsher disconnect() handling [#3509]
Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
1 parent c8f8269 commit db05b67

3 files changed

Lines changed: 3 additions & 24 deletions

File tree

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,14 +1027,7 @@ class gui_updater( threading.Thread ) :
10271027
# Teardown old connection handler properly
10281028
old_handler = self.__parent_class._interface__ups_handler
10291029
if old_handler is not None:
1030-
try:
1031-
# Close the underlying telnet connection if it exists
1032-
if hasattr(old_handler, '_PyNUTClient__tn') and old_handler._PyNUTClient__tn is not None:
1033-
old_handler._PyNUTClient__tn.close()
1034-
elif hasattr(old_handler, 'tn') and old_handler.tn is not None:
1035-
old_handler.tn.close()
1036-
except Exception:
1037-
pass # Best effort cleanup
1030+
old_handler.disconnect()
10381031
del old_handler
10391032

10401033
# Create a new connection handler

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,14 +1087,7 @@ class gui_updater :
10871087
# Teardown old connection handler properly
10881088
old_handler = self.__parent_class._interface__ups_handler
10891089
if old_handler is not None:
1090-
try:
1091-
# Close the underlying telnet connection if it exists
1092-
if hasattr(old_handler, '_PyNUTClient__tn') and old_handler._PyNUTClient__tn is not None:
1093-
old_handler._PyNUTClient__tn.close()
1094-
elif hasattr(old_handler, 'tn') and old_handler.tn is not None:
1095-
old_handler.tn.close()
1096-
except Exception:
1097-
pass # Best effort cleanup
1090+
old_handler.disconnect()
10981091
del old_handler
10991092

11001093
# Create a new connection handler

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,14 +1112,7 @@ class gui_updater :
11121112
# Teardown old connection handler properly
11131113
old_handler = self.__parent_class._interface__ups_handler
11141114
if old_handler is not None:
1115-
try:
1116-
# Close the underlying telnet connection if it exists
1117-
if hasattr(old_handler, '_PyNUTClient__tn') and old_handler._PyNUTClient__tn is not None:
1118-
old_handler._PyNUTClient__tn.close()
1119-
elif hasattr(old_handler, 'tn') and old_handler.tn is not None:
1120-
old_handler.tn.close()
1121-
except Exception:
1122-
pass # Best effort cleanup
1115+
old_handler.disconnect()
11231116
del old_handler
11241117

11251118
# Create a new connection handler

0 commit comments

Comments
 (0)