[PATCH 1 of 5 STABLE V2] worker: move killworkers and waitforworkers up
Jun Wu
quark at fb.com
Thu Jul 28 20:50:04 UTC 2016
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1469735397 -3600
# Thu Jul 28 20:49:57 2016 +0100
# Node ID 391a26627ecf994c767c01125843184cfed49de4
# Parent 8421cbebc783e7f3cb17cfb62b4095113f8d666b
# Available At https://bitbucket.org/quark-zju/hg-draft
# hg pull https://bitbucket.org/quark-zju/hg-draft -r 391a26627ecf
worker: move killworkers and waitforworkers up
We need to use them in the SIGCHLD handler and SIGCHLD handler should be
installed before fork.
diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -86,6 +86,20 @@ def _posixworker(ui, func, staticargs, a
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:
@@ -103,20 +117,6 @@ def _posixworker(ui, func, staticargs, a
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():
More information about the Mercurial-devel
mailing list