##// END OF EJS Templates
procutil: allow callers of runbgcommand to assume the process starts...
Augie Fackler -
r42696:ca1014ad default
parent child Browse files
Show More
@@ -470,7 +470,8 b' if pycompat.iswindows:'
470 # See https://phab.mercurial-scm.org/D1701 for discussion
470 # See https://phab.mercurial-scm.org/D1701 for discussion
471 _creationflags = DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP
471 _creationflags = DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP
472
472
473 def runbgcommand(script, env, shell=False, stdout=None, stderr=None):
473 def runbgcommand(
474 script, env, shell=False, stdout=None, stderr=None, ensurestart=True):
474 '''Spawn a command without waiting for it to finish.'''
475 '''Spawn a command without waiting for it to finish.'''
475 # we can't use close_fds *and* redirect stdin. I'm not sure that we
476 # we can't use close_fds *and* redirect stdin. I'm not sure that we
476 # need to because the detached process has no console connection.
477 # need to because the detached process has no console connection.
@@ -480,12 +481,15 b' if pycompat.iswindows:'
480 creationflags=_creationflags, stdout=stdout,
481 creationflags=_creationflags, stdout=stdout,
481 stderr=stderr)
482 stderr=stderr)
482 else:
483 else:
483 def runbgcommand(cmd, env, shell=False, stdout=None, stderr=None):
484 def runbgcommand(
485 cmd, env, shell=False, stdout=None, stderr=None, ensurestart=True):
484 '''Spawn a command without waiting for it to finish.'''
486 '''Spawn a command without waiting for it to finish.'''
485 # double-fork to completely detach from the parent process
487 # double-fork to completely detach from the parent process
486 # based on http://code.activestate.com/recipes/278731
488 # based on http://code.activestate.com/recipes/278731
487 pid = os.fork()
489 pid = os.fork()
488 if pid:
490 if pid:
491 if not ensurestart:
492 return
489 # Parent process
493 # Parent process
490 (_pid, status) = os.waitpid(pid, 0)
494 (_pid, status) = os.waitpid(pid, 0)
491 if os.WIFEXITED(status):
495 if os.WIFEXITED(status):
General Comments 0
You need to be logged in to leave comments. Login now