[PATCH 7 of 8 V4] worker: add a SIGCHLD handler to collect worker immediately

Jun Wu quark at fb.com
Fri Nov 11 22:11:38 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1478920042 0
#      Sat Nov 12 03:07:22 2016 +0000
# Node ID 7492186538a69cdfad28cb93093d7f7077942ca3
# Parent  596cee9d5c12dcfa2d272b5441d5060a26a6440c
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 7492186538a6
worker: add a SIGCHLD handler to collect worker immediately

As planned by previous patches, add a SIGCHLD handler to get notifications
about worker exits, and deals with worker failure immediately.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -126,8 +126,12 @@ def _posixworker(ui, func, staticargs, a
                 problem[0] = st
                 killworkers()
+    def sigchldhandler(signum, frame):
+        waitforworkers(blocking=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)
@@ -147,4 +151,5 @@ def _posixworker(ui, func, staticargs, a
         signal.signal(signal.SIGINT, oldhandler)
         t.join()
+        signal.signal(signal.SIGCHLD, oldchldhandler)
         status = problem[0]
         if status:


More information about the Mercurial-devel mailing list