[PATCH 5 of 5 STABLE V2] worker: add a SIGCHLD handler

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


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1469737655 -3600
#      Thu Jul 28 21:27:35 2016 +0100
# Node ID 862244b11d9db6df3d6b07756cfab06b5768d17f
# Parent  3e52c87875599106cd17b264df93c903a3876dfb
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 862244b11d9d
worker: add a SIGCHLD handler

As planned, we add a SIGCHLD handler to notice and handle child failure
immediately.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -110,10 +110,14 @@ def _posixworker(ui, func, staticargs, a
             if st and not problem[0]:
                 problem[0] = st
                 killworkers()
+    def sigchldhandler(signum, frame):
+        waitforworkers(False)
+    oldchldhandler = signal.signal(signal.SIGCHLD, sigchldhandler)
     for pargs in partition(args, workers):
         pid = os.fork()
         if pid == 0:
             signal.signal(signal.SIGINT, oldhandler)
+            signal.signal(signal.SIGCHLD, oldchldhandler)
             try:
                 os.close(rfd)
                 for i, item in func(*(staticargs + (pargs,))):
@@ -132,6 +136,7 @@ def _posixworker(ui, func, staticargs, a
     def cleanup():
         signal.signal(signal.SIGINT, oldhandler)
         t.join()
+        signal.signal(signal.SIGCHLD, oldchldhandler)
         status = problem[0]
         if status:
             if status < 0:


More information about the Mercurial-devel mailing list