From ebd5f60962878a4f9cd7ceae9a4adb6b37e6829b Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Fri, 11 Mar 2016 18:20:20 +0100 Subject: [PATCH] Close the hddtemp socket in the finally block This way we avoid leaving sockets open which can trigger a ResourceWarning in some cases. --- glances/plugins/glances_hddtemp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/glances/plugins/glances_hddtemp.py b/glances/plugins/glances_hddtemp.py index e6343536..8a1347c4 100644 --- a/glances/plugins/glances_hddtemp.py +++ b/glances/plugins/glances_hddtemp.py @@ -130,12 +130,13 @@ class GlancesGrabHDDTemp(object): sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sck.connect((self.host, self.port)) data = sck.recv(4096) - sck.close() except socket.error as e: logger.warning("Can not connect to an HDDtemp server ({0}:{1} => {2})".format(self.host, self.port, e)) logger.debug("Disable the HDDtemp module. Use the --disable-hddtemp to hide the previous message.") self.args.disable_hddtemp = True data = "" + finally: + sck.close() return data