Mercurial > public > mercurial-scm > hg
comparison mercurial/worker.py @ 30412:7bc25549e084
worker: allow waitforworkers to be non-blocking
This patch adds a boolean flag to waitforworkers and makes it non-blocking
if set to True.
This is to make it possible that we can reap our workers while keep other
unrelated children untouched, after receiving SIGCHLD.
author | Jun Wu <quark@fb.com> |
---|---|
date | Thu, 28 Jul 2016 20:57:07 +0100 |
parents | 47de34f79f93 |
children | 9c25a1a8c685 |
comparison
equal
deleted
inserted
replaced
30411:47de34f79f93 | 30412:7bc25549e084 |
---|---|
95 try: | 95 try: |
96 os.kill(p, signal.SIGTERM) | 96 os.kill(p, signal.SIGTERM) |
97 except OSError as err: | 97 except OSError as err: |
98 if err.errno != errno.ESRCH: | 98 if err.errno != errno.ESRCH: |
99 raise | 99 raise |
100 def waitforworkers(): | 100 def waitforworkers(blocking=True): |
101 for pid in pids: | 101 for pid in pids: |
102 st = _exitstatus(os.waitpid(pid, 0)[1]) | 102 p, st = os.waitpid(pid, 0 if blocking else os.WNOHANG) |
103 if p: | |
104 st = _exitstatus(st) | |
103 if st and not problem[0]: | 105 if st and not problem[0]: |
104 problem[0] = st | 106 problem[0] = st |
105 killworkers() | 107 killworkers() |
106 for pargs in partition(args, workers): | 108 for pargs in partition(args, workers): |
107 pid = os.fork() | 109 pid = os.fork() |