changeset 18708:86524a70c0f6

worker: fix a race in SIGINT handling This is almost impossible to trigger due to the tiny time window involved.
author Bryan O'Sullivan <bryano@fb.com>
date Wed, 20 Feb 2013 11:31:31 -0800
parents d1a2b086d058
children 9955fc5ee24b
files mercurial/worker.py
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/worker.py	Wed Feb 20 11:31:27 2013 -0800
+++ b/mercurial/worker.py	Wed Feb 20 11:31:31 2013 -0800
@@ -75,9 +75,12 @@
 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 @@
                 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)