changeset 40895:9f00de4dc7cb

commandserver: remove redundant "if True" block
author Yuya Nishihara <yuya@tcha.org>
date Wed, 31 Oct 2018 22:03:07 +0900
parents dc9901558e3c
children 2525faf4ecdb
files mercurial/commandserver.py
diffstat 1 files changed, 25 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commandserver.py	Wed Oct 31 22:02:38 2018 +0900
+++ b/mercurial/commandserver.py	Wed Oct 31 22:03:07 2018 +0900
@@ -570,35 +570,34 @@
 
     def _acceptnewconnection(self, sock, selector):
         h = self._servicehandler
-        if True:
+        try:
+            conn, _addr = sock.accept()
+        except socket.error as inst:
+            if inst.args[0] == errno.EINTR:
+                return
+            raise
+
+        pid = os.fork()
+        if pid:
             try:
-                conn, _addr = sock.accept()
-            except socket.error as inst:
-                if inst.args[0] == errno.EINTR:
-                    return
-                raise
-
-            pid = os.fork()
-            if pid:
+                self.ui.log(b'cmdserver', b'forked worker process (pid=%d)\n',
+                            pid)
+                self._workerpids.add(pid)
+                h.newconnection()
+            finally:
+                conn.close()  # release handle in parent process
+        else:
+            try:
+                selector.close()
+                sock.close()
+                self._runworker(conn)
+                conn.close()
+                os._exit(0)
+            except:  # never return, hence no re-raises
                 try:
-                    self.ui.log(b'cmdserver',
-                                b'forked worker process (pid=%d)\n', pid)
-                    self._workerpids.add(pid)
-                    h.newconnection()
+                    self.ui.traceback(force=True)
                 finally:
-                    conn.close()  # release handle in parent process
-            else:
-                try:
-                    selector.close()
-                    sock.close()
-                    self._runworker(conn)
-                    conn.close()
-                    os._exit(0)
-                except:  # never return, hence no re-raises
-                    try:
-                        self.ui.traceback(force=True)
-                    finally:
-                        os._exit(255)
+                    os._exit(255)
 
     def _sigchldhandler(self, signal, frame):
         self._reapworkers(os.WNOHANG)