[PATCH 3 of 5 STABLE V2] worker: allow waitforworkers to be non-blocking

Jun Wu quark at fb.com
Thu Jul 28 16:50:06 EDT 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1469735827 -3600
#      Thu Jul 28 20:57:07 2016 +0100
# Node ID 57c3b5c1b41333faa4062720ae50bf93c187ce88
# Parent  644e4dfd02fa16e77e550113cafe4fca3d0a9c69
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 57c3b5c1b413
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.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -94,9 +94,11 @@ def _posixworker(ui, func, staticargs, a
             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(s)
             if st and not problem[0]:
                 problem[0] = st
                 killworkers()


More information about the Mercurial-devel mailing list