Patchwork D6537: procutil: allow callers of runbgcommand to assume the process starts

login
register
mail settings
Submitter phabricator
Date June 18, 2019, 2:02 p.m.
Message ID <8ae00ad014cdf0d93fb6701415b67406@localhost.localdomain>
Download mbox | patch
Permalink /patch/40582/
State Not Applicable
Headers show

Comments

phabricator - June 18, 2019, 2:02 p.m.
durin42 updated this revision to Diff 15575.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6537?vs=15572&id=15575

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6537/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6537

AFFECTED FILES
  mercurial/utils/procutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -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):