Mercurial > hg-stable
changeset 30420:7a5d6e2fd2d5
worker: move killworkers and waitforworkers up
We need to use them in the SIGCHLD handler and SIGCHLD handler should be
installed before fork.
author | Jun Wu <quark@fb.com> |
---|---|
date | Thu, 28 Jul 2016 20:49:57 +0100 |
parents | 0852161588c6 |
children | 47de34f79f93 |
files | mercurial/worker.py |
diffstat | 1 files changed, 14 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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():