worker: move killworkers and waitforworkers up
authorJun Wu <quark@fb.com>
Thu, 28 Jul 2016 20:49:57 +0100
changeset 30410 7a5d6e2fd2d5
parent 30409 0852161588c6
child 30411 47de34f79f93
worker: move killworkers and waitforworkers up We need to use them in the SIGCHLD handler and SIGCHLD handler should be installed before fork.
mercurial/worker.py
--- a/mercurial/worker.py	Fri Nov 11 21:11:17 2016 +0000
+++ b/mercurial/worker.py	Thu Jul 28 20:49:57 2016 +0100
@@ -89,6 +89,20 @@
     oldhandler = signal.getsignal(signal.SIGINT)
     signal.signal(signal.SIGINT, signal.SIG_IGN)
     pids, problem = [], [0]
+    def killworkers():
+        # if one worker bails, there's no good reason to wait for the rest
+        for p in pids:
+            try:
+                os.kill(p, signal.SIGTERM)
+            except OSError as err:
+                if err.errno != errno.ESRCH:
+                    raise
+    def waitforworkers():
+        for _pid in pids:
+            st = _exitstatus(os.wait()[1])
+            if st and not problem[0]:
+                problem[0] = st
+                killworkers()
     for pargs in partition(args, workers):
         pid = os.fork()
         if pid == 0:
@@ -106,20 +120,6 @@
     pids.reverse()
     os.close(wfd)
     fp = os.fdopen(rfd, 'rb', 0)
-    def killworkers():
-        # if one worker bails, there's no good reason to wait for the rest
-        for p in pids:
-            try:
-                os.kill(p, signal.SIGTERM)
-            except OSError as err:
-                if err.errno != errno.ESRCH:
-                    raise
-    def waitforworkers():
-        for _pid in pids:
-            st = _exitstatus(os.wait()[1])
-            if st and not problem[0]:
-                problem[0] = st
-                killworkers()
     t = threading.Thread(target=waitforworkers)
     t.start()
     def cleanup():