# HG changeset patch # User Siddharth Agarwal # Date 2013-10-02 22:17:50 # Node ID edce20ebe1f3434367796747f802fe74e23ede9b # Parent 993b2448867994252aebdc0ed04e69572d57e811 cmdutil.service: move pidfile writing to a local function An upcoming patch will reuse this code. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -468,6 +468,13 @@ def service(opts, parentfn=None, initfn= runargs=None, appendpid=False): '''Run a command as a service.''' + def writepid(pid): + if opts['pid_file']: + mode = appendpid and 'a' or 'w' + fp = open(opts['pid_file'], mode) + fp.write(str(pid) + '\n') + fp.close() + if opts['daemon'] and not opts['daemon_pipefds']: # Signal child process startup with file removal lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-') @@ -504,11 +511,7 @@ def service(opts, parentfn=None, initfn= if initfn: initfn() - if opts['pid_file']: - mode = appendpid and 'a' or 'w' - fp = open(opts['pid_file'], mode) - fp.write(str(os.getpid()) + '\n') - fp.close() + writepid(os.getpid()) if opts['daemon_pipefds']: lockpath = opts['daemon_pipefds']