Patchwork [2,of,7,V3] worker: wait worker pid explicitly

mail settings
Submitter Jun Wu
Date Aug. 4, 2016, 6:29 p.m.
Message ID <284b68b409012f28ee4c.1470335343@x1c>
Download mbox | patch
Permalink /patch/16094/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show


Jun Wu - Aug. 4, 2016, 6:29 p.m.
# HG changeset patch
# User Jun Wu <>
# Date 1469735480 -3600
#      Thu Jul 28 20:51:20 2016 +0100
# Node ID 284b68b409012f28ee4cd7bf520af24d5fb87a02
# Parent  f6d3fb7e8a53968a5be72ed1f89d4abc693e7e27
# Available At
#              hg pull -r 284b68b40901
worker: wait worker pid explicitly

Before this patch, waitforworkers uses os.wait() to collect child workers, and
only wait len(pids) processes. This can have serious issues if other code
spawns new processes and does not reap them: 1. may get wrong exit
code and kill innocent workers. 2. may continue without waiting for
all workers to complete.

This patch fixes the issue by using waitpid to wait worker pid explicitly.

However, this patch introduces a new issue: worker failure may not be handled
immediately. The issue will be addressed in next patches.


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -95,8 +95,8 @@  def _posixworker(ui, func, staticargs, a
                 if err.errno != errno.ESRCH:
     def waitforworkers():
-        for _pid in pids:
-            st = _exitstatus(os.wait()[1])
+        for pid in pids:
+            st = _exitstatus(os.waitpid(pid, 0)[1])
             if st and not problem[0]:
                 problem[0] = st