Mercurial > hg
changeset 42496:ca1014ad3de4
procutil: allow callers of runbgcommand to assume the process starts
Experimentally starting the subprocess can take as much as 40ms, and
for some of our use cases that's frivolous: we know the binary will
start, and if it doesn't we'd only ever ignore it and continue
anyway. This lets those use cases be faster.
Differential Revision: https://phab.mercurial-scm.org/D6537
author | Augie Fackler <augie@google.com> |
---|---|
date | Tue, 18 Jun 2019 09:43:27 -0400 |
parents | 373aeede7352 |
children | df1419c5756a |
files | mercurial/utils/procutil.py |
diffstat | 1 files changed, 6 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/utils/procutil.py Tue Jun 18 09:58:01 2019 -0400 +++ b/mercurial/utils/procutil.py Tue Jun 18 09:43:27 2019 -0400 @@ -470,7 +470,8 @@ # See https://phab.mercurial-scm.org/D1701 for discussion _creationflags = DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP - def runbgcommand(script, env, shell=False, stdout=None, stderr=None): + def runbgcommand( + script, env, shell=False, stdout=None, stderr=None, ensurestart=True): '''Spawn a command without waiting for it to finish.''' # we can't use close_fds *and* redirect stdin. I'm not sure that we # need to because the detached process has no console connection. @@ -480,12 +481,15 @@ creationflags=_creationflags, stdout=stdout, stderr=stderr) else: - def runbgcommand(cmd, env, shell=False, stdout=None, stderr=None): + def runbgcommand( + cmd, env, shell=False, stdout=None, stderr=None, ensurestart=True): '''Spawn a command without waiting for it to finish.''' # double-fork to completely detach from the parent process # based on http://code.activestate.com/recipes/278731 pid = os.fork() if pid: + if not ensurestart: + return # Parent process (_pid, status) = os.waitpid(pid, 0) if os.WIFEXITED(status):