Patchwork [5,of,7,V3] worker: add a SIGCHLD handler

login
register
mail settings
Submitter Jun Wu
Date Aug. 4, 2016, 6:29 p.m.
Message ID <d179a66b0b15988687ba.1470335346@x1c>
Download mbox | patch
Permalink /patch/16096/
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 1469737655 -3600
#      Thu Jul 28 21:27:35 2016 +0100
# Node ID d179a66b0b15988687ba9d69c5b76e4464a457eb
# Parent  74a3dd438c5645cc1a685e788d86e70698bfe6c9
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r d179a66b0b15
worker: add a SIGCHLD handler

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

Patch

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: