[PATCH 3 of 8 V4] worker: allow waitforworkers to be non-blocking

Sean Farley sean at farley.io
Mon Nov 14 17:29:46 EST 2016


Jun Wu <quark at fb.com> writes:

> Excerpts from Sean Farley's message of 2016-11-14 13:42:35 -0800:
>> Jun Wu <quark at fb.com> writes:
>> 
>> > # HG changeset patch
>> > # User Jun Wu <quark at fb.com>
>> > # Date 1469735827 -3600
>> > #      Thu Jul 28 20:57:07 2016 +0100
>> > # Node ID 15594c001edb494e4ee4faff6fc6730772271768
>> > # Parent  05485a528446de24eb8b81819f66ad36f0730802
>> > # Available At https://bitbucket.org/quark-zju/hg-draft 
>> > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r 15594c001edb
>> > 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.
>> >
>> > diff --git a/mercurial/worker.py b/mercurial/worker.py
>> > --- a/mercurial/worker.py
>> > +++ b/mercurial/worker.py
>> > @@ -95,7 +95,9 @@ def _posixworker(ui, func, staticargs, a
>> >                  if err.errno != errno.ESRCH:
>> >                      raise
>> > -    def waitforworkers():
>> > +    def waitforworkers(blocking=True):
>> >          for pid in pids:
>> > -            st = _exitstatus(os.waitpid(pid, 0)[1])
>> > +            p, st = os.waitpid(pid, 0 if blocking else os.WNOHANG)
>> 
>> Minor nit: is if/else pattern this allowed?
>
> Searching the codebase, I could find other places using the pattern.
> I guess a pair of parentheses would make it look better.

Fair enough. I couldn't remember.


More information about the Mercurial-devel mailing list