worker: move killworkers and waitforworkers up
We need to use them in the SIGCHLD handler and SIGCHLD handler should be
installed before fork.
--- a/mercurial/worker.py Fri Nov 11 21:11:17 2016 +0000
+++ b/mercurial/worker.py Thu Jul 28 20:49:57 2016 +0100
@@ -89,6 +89,20 @@
oldhandler = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, signal.SIG_IGN)
pids, problem = [], [0]
+ def killworkers():
+ # if one worker bails, there's no good reason to wait for the rest
+ for p in pids:
+ try:
+ os.kill(p, signal.SIGTERM)
+ except OSError as err:
+ if err.errno != errno.ESRCH:
+ raise
+ def waitforworkers():
+ for _pid in pids:
+ st = _exitstatus(os.wait()[1])
+ if st and not problem[0]:
+ problem[0] = st
+ killworkers()
for pargs in partition(args, workers):
pid = os.fork()
if pid == 0:
@@ -106,20 +120,6 @@
pids.reverse()
os.close(wfd)
fp = os.fdopen(rfd, 'rb', 0)
- def killworkers():
- # if one worker bails, there's no good reason to wait for the rest
- for p in pids:
- try:
- os.kill(p, signal.SIGTERM)
- except OSError as err:
- if err.errno != errno.ESRCH:
- raise
- def waitforworkers():
- for _pid in pids:
- st = _exitstatus(os.wait()[1])
- if st and not problem[0]:
- problem[0] = st
- killworkers()
t = threading.Thread(target=waitforworkers)
t.start()
def cleanup():