worker: allow waitforworkers to be non-blocking
authorJun Wu <quark@fb.com>
Thu, 28 Jul 2016 20:57:07 +0100
changeset 30422 7bc25549e084
parent 30421 47de34f79f93
child 30423 9c25a1a8c685
worker: allow waitforworkers to be non-blocking This patch adds a boolean flag to waitforworkers and makes it non-blocking if set to True. This is to make it possible that we can reap our workers while keep other unrelated children untouched, after receiving SIGCHLD.
mercurial/worker.py
--- a/mercurial/worker.py	Thu Jul 28 20:51:20 2016 +0100
+++ b/mercurial/worker.py	Thu Jul 28 20:57:07 2016 +0100
@@ -97,9 +97,11 @@
             except OSError as err:
                 if err.errno != errno.ESRCH:
                     raise
-    def waitforworkers():
+    def waitforworkers(blocking=True):
         for pid in pids:
-            st = _exitstatus(os.waitpid(pid, 0)[1])
+            p, st = os.waitpid(pid, 0 if blocking else os.WNOHANG)
+            if p:
+                st = _exitstatus(st)
             if st and not problem[0]:
                 problem[0] = st
                 killworkers()