[PATCH 2 of 3 v2] worker: fix a race in SIGINT handling

Bryan O'Sullivan bos at serpentine.com
Tue Feb 19 14:54:05 CST 2013


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1361307231 28800
# Node ID e0bdbbb4e62ae8e1b588d39f514b59557fe75cfc
# Parent  bd5bb50f9f1660152459d13b921e599b8af96b13
worker: fix a race in SIGINT handling

This is almost impossible to trigger due to the tiny time window involved.

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -75,9 +75,12 @@ def worker(ui, costperarg, func, statica
 def _posixworker(ui, func, staticargs, args):
     rfd, wfd = os.pipe()
     workers = _numworkers(ui)
+    oldhandler = signal.getsignal(signal.SIGINT)
+    signal.signal(signal.SIGINT, signal.SIG_IGN)
     for pargs in partition(args, workers):
         pid = os.fork()
         if pid == 0:
+            signal.signal(signal.SIGINT, oldhandler)
             try:
                 os.close(rfd)
                 for i, item in func(*(staticargs + (pargs,))):
@@ -87,8 +90,6 @@ def _posixworker(ui, func, staticargs, a
                 os._exit(255)
     os.close(wfd)
     fp = os.fdopen(rfd, 'rb', 0)
-    oldhandler = signal.getsignal(signal.SIGINT)
-    signal.signal(signal.SIGINT, signal.SIG_IGN)
     def cleanup():
         # python 2.4 is too dumb for try/yield/finally
         signal.signal(signal.SIGINT, oldhandler)


More information about the Mercurial-devel mailing list