Patchwork [3,of,8,V5] worker: allow waitforworkers to be non-blocking

login
register
mail settings
Submitter Jun Wu
Date Nov. 15, 2016, 2:39 a.m.
Message ID <0abdc39524ef9845a820.1479177546@x1c>
Download mbox | patch
Permalink /patch/17577/
State Accepted
Headers show

Comments

Jun Wu - Nov. 15, 2016, 2:39 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1469735827 -3600
#      Thu Jul 28 20:57:07 2016 +0100
# Node ID 0abdc39524ef9845a82082f53499d83468ce7761
# Parent  946a4a33ad2fbb4a060af6f32f0a96a63d01a6e8
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 0abdc39524ef
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
@@ -98,7 +98,9 @@  def _posixworker(ui, func, staticargs, a
                 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