Browse Source

[1828] Cleanup code by using with

Mukund Sivaraman 13 years ago
parent
commit
9040c49022
1 changed files with 7 additions and 9 deletions
  1. 7 9
      src/bin/xfrout/xfrout.py.in

+ 7 - 9
src/bin/xfrout/xfrout.py.in

@@ -798,15 +798,13 @@ class UnixSockServer(socketserver_mixin.NoPollMixIn,
         '''Check whether the socket file 'sock_file' exists and
         is being used by one running xfrout process. If it is,
         return True, or else return False. '''
-        try:
-            sock = socket.socket(socket.AF_UNIX)
-            sock.connect(sock_file)
-        except socket.error as err:
-            sock.close()
-            return False
-        else:
-            sock.close()
-            return True
+        with socket.socket(socket.AF_UNIX) as sock:
+            try:
+                sock.connect(sock_file)
+            except socket.error as err:
+                return False
+            else:
+                return True
 
     def shutdown(self):
         self._write_sock.send(b"shutdown") #terminate the xfrout session thread