worker: fix a race in SIGINT handling
This is almost impossible to trigger due to the tiny time window involved.
--- 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)