worker: fix a race in SIGINT handling
authorBryan O'Sullivan <bryano@fb.com>
Wed, 20 Feb 2013 11:31:31 -0800
changeset 18708 86524a70c0f6
parent 18707 d1a2b086d058
child 18709 9955fc5ee24b
worker: fix a race in SIGINT handling This is almost impossible to trigger due to the tiny time window involved.
mercurial/worker.py
--- 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)