Patchwork [3,of,7,V3] worker: allow waitforworkers to be non-blocking

login
register
mail settings
Submitter Jun Wu
Date Aug. 4, 2016, 6:29 p.m.
Message ID <521d7fac970d711766e6.1470335344@x1c>
Download mbox | patch
Permalink /patch/16100/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - Aug. 4, 2016, 6:29 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1469735827 -3600
#      Thu Jul 28 20:57:07 2016 +0100
# Node ID 521d7fac970d711766e61b7b54d20ddefc4be406
# Parent  284b68b409012f28ee4cd7bf520af24d5fb87a02
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 521d7fac970d
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.

Patch

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(st)
             if st and not problem[0]:
                 problem[0] = st
                 killworkers()